具有相同端口的不同VirtualHosts

时间:2011-05-20 09:23:17

标签: apache virtualhost virtual-hosts

我需要为不同的项目和不同的日志提供两个具有相同监听端口的VirtualHost。这就是我所拥有的:

<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>

2 个答案:

答案 0 :(得分:25)

在所有虚拟主机中添加不同的ServerName指令:

<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>

不要忘记在dev.localhost中将my-project.localhost/etc/hosts的主机条目添加到127.0.0.1或您希望它指向的任何IP。

答案 1 :(得分:0)

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

//尝试添加错误文档

ErrorDocument 404 404.html

需要在您的应用程序中创建反馈。