本文介绍了阿帕奇:在同一端口设置不同virtualhosts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要在同一个监听端口不同的项目和日志,例如:

 <虚拟主机*:80>
        的DocumentRoot /家庭/项目/ SMK
        错误日志/var/log/apache2/smk-error.log        RedirectMatch ^ / $ / CMS
< /虚拟主机><虚拟主机*:80>
        的DocumentRoot /家庭/项目/ SMK / CMS
        错误日志/var/log/apache2/smk-cms-error.log
< /虚拟主机><虚拟主机*:80>
        的DocumentRoot /家庭/项目/ SMK /部署
        错误日志/var/log/apache2/smk-deploy-error.log
< /虚拟主机>

解决方案的结果。

Apache的配置:

 了NameVirtualHost *:80
听80
<虚拟主机*:80>
        服务器名本地主机:80
        的DocumentRoot /家庭/项目/ SMK
    错误日志/var/log/apache2/smk-error.log
< /虚拟主机>
<虚拟主机*:80>
        的DocumentRoot /家庭/项目/ SMK / CMS
        服务器名cms.localhost
    错误日志/var/log/apache2/smk-cms-error.lo
< /虚拟主机>

/ etc / hosts中配置:

  127.0.0.1 cms.localhost cms.localhost


解决方案

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

 <虚拟主机*:80>
        服务器名dev.localhost
        的DocumentRoot /家庭/项目/ SMK / CMS
        错误日志/var/log/apache2/smk-cms-error.log
< /虚拟主机><虚拟主机*:80>
        SERVERNAME我-project.localhost
        的DocumentRoot /家庭/项目/ SMK /部署
        错误日志/var/log/apache2/smk-deploy-error.log
< /虚拟主机>

不要忘了添加主机条目 dev.localhost 我-project.localhost / etc / hosts中 127.0.0.1 或任何IP,你希望它指向。

Hi everybody i need to have in the same listen port different projects and logs, example:

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

Solution result

Apache configuration:

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


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

/etc/hosts configuration:

127.0.0.1       cms.localhost           cms.localhost
解决方案

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.

这篇关于阿帕奇:在同一端口设置不同virtualhosts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:32