繁体   English   中英

如何设置VirtualHosts将同一IP上的两个端口指向不同的ServerNames?

[英]How do I setup VirtualHosts to point two ports on same IP to different ServerNames?

我已经将wiki软件Gitit设置为在同一个Apache服务器的两个独立端口上运行(端口1848和4000)。 我已经确认他们正在运行:

http://wcaleb.rice.edu:4000
http://wcaleb.rice.edu:1848

现在我想将这两个网站代理为更漂亮的网址,例如http://wiki.wcaleb.rice.eduhttp://hist118.wcaleb.rice.edu 两者的IP地址是128.42.173.84

我的服务器管理员已经为这些名称添加了DNS条目,但我似乎无法让我的Apache配置工作。 按照这里说明 ,我尝试设置如下的VirtualHost:

NameVirtualHost *:1848

<VirtualHost *:1848>
    ServerName hist118.wcaleb.rice.edu
    DocumentRoot /var/www/
    RewriteEngine On
    ProxyPreserveHost On
    ProxyRequests Off

    <Proxy *>
       Order deny,allow
       Allow from all
    </Proxy>

    ProxyPassReverse /    http://127.0.0.1:1848
    RewriteRule ^(.*) http://127.0.0.1:1848$1 [P]

    ErrorLog /var/log/apache2/error.log
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

</VirtualHost>

另一个类似于端口4000上的http://wiki.wcaleb.rice.edu的虚拟主机。但是当我发出service httpd restart ,我在启动httpd时收到一条FAILED消息,而我的浏览器无法连接到http:/ /hist118.wcaleb.rice.edu

据我所知,我的httpd.conf的其余部分是发行版附带的默认文件。 我的服务器正在RedHat Enterprise机器上运行。 我是Apache的新手,所以我确定这里有一个明显的答案,但在对配置进行各种调整后,我无法弄清楚我做错了什么。

NameVirtualHostVirtualHost上删除:1848 (或将其更改为:80 )。 这个练习的重点是让Apache监听这些主机名的默认HTTP端口(端口80)以及Gitit正在侦听的高端口的代理流量。

这是你需要做的。

    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName hist118.wcaleb.rice.edu
        DocumentRoot /var/www/
        RewriteEngine On
        ProxyPreserveHost On
        ProxyRequests Off

        <Proxy *>
           Order deny,allow
           Allow from all
        </Proxy>

        ProxyPassReverse /    http://127.0.0.1:1848
        RewriteRule ^(.*) http://127.0.0.1:1848$1 [P]

        ErrorLog /var/log/apache2/error.log
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

</VirtualHost>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM