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

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 深海控制器DSE7320MKII和博世ECU间can通讯知识
    • ¥15 Ru的复折射率用于FDTD 200nm到1200nm
    • ¥15 使用Fiddler抓包,textview的乱码如何解决
    • ¥50 trio连接驱动器报错
    • ¥15 有谁懂nhanes的权重计算啊
    • ¥15 欧姆龙PLC 电机控制 限位
    • ¥30 如何处理shell命令接收到的视频流并实时播放出来
    • ¥15 虚心请教C#的代码优化问题
    • ¥15 有偿求做台风过境全过程模拟仿真
    • ¥50 求!AutomationDesk 如何自动导入Variant数据