Different VirtualHosts with the same port

我与影子孤独终老i 提交于 2019-11-29 02:18:54

问题


I need to have two VirtualHosts with the same listen port for different projects and with different logs. Here's what I've got:

<VirtualHost *:80>
        DocumentRoot /home/projects/smk
        ErrorLog /var/log/apache2/smk-error.log
        RedirectMatch ^/$ /cms
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /home/projects/smk/cms
        ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /home/projects/smk/deploy
        ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>

回答1:


Add different ServerName directive in all virtual hosts:

<VirtualHost *:80>
        ServerName dev.localhost
        DocumentRoot /home/projects/smk/cms
        ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>

<VirtualHost *:80>
        ServerName my-project.localhost
        DocumentRoot /home/projects/smk/deploy
        ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>

Don't forget to add host-entries for dev.localhost and my-project.localhost in /etc/hosts to 127.0.0.1 or whatever ip you want it to point to.




回答2:


ServerName my-project.localhost DocumentRoot /home/projects/smk/deploy ErrorLog /var/log/apache2/smk-deploy-error.log

//Try adding Error document

ErrorDocument 404 404.html

There is a need to create a feedback in your application.



来源:https://stackoverflow.com/questions/6069892/different-virtualhosts-with-the-same-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!