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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler