donglu4633 2016-06-03 14:46
浏览 239
已采纳

apache2.conf和httpd.conf

After reading ubuntu AMP community and Apache 2.4 configuration.

I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4

In XAMP you would assign an extra number to your httpd-vhost.conf like this:

Listen *:9000 
<virtualhost *:9000>  
    ServerName localhost 
    DocumentRoot "~/xamp/apache2/htdocs/html/app-name/" 
</virtualhost> 

<Directory "~/xamp/apache2/htdocs/html/app-name/">  
    Options Indexes FollowSymLinks  
    AllowOverride all 
</Directory>

Then Edit your httpd.conf files like:

//....Some code.....   */ 
<Directory>
    AllowOverride all
<Directory /> 
//...Some code...

and uncomment this line:

//....Some code.....   */ 

# Virtual hosts
include conf/extra/httpd-vhosts.conf 

//...Some code...

My question is:

Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?

Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.

  • 写回答

1条回答 默认 最新

  • duanjing4667 2016-06-03 15:22
    关注

    What works is the following in (for example) your 000-default.conf:

    <VirtualHost *:80>
        ServerName site1.vm
    
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/site1/web/
    
        ErrorLog ${APACHE_LOG_DIR}/site1_error.log
        CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
    
        <Directory /var/www/site1/web/>
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName site2.vm
    
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/site2/web/
    
        ErrorLog ${APACHE_LOG_DIR}/site2_error.log
        CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
    
        <Directory /var/www/site2/web/>
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    

    This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)