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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献