【问题标题】:How do I setup VirtualHosts to point two ports on same IP to different ServerNames?如何设置虚拟主机以将同一 IP 上的两个端口指向不同的服务器名称?
【发布时间】:2012-12-09 04:08:52
【问题描述】:

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

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

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

我的服务器管理员已为这些名称添加了 DNS 条目,但我似乎无法让我的 Apache 配置正常工作。在instructions here之后,我尝试像这样设置一个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>

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

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

【问题讨论】:

  • 这个问题更适合serverfault
  • 你可以尝试直接运行httpd -t让它检查语法,你可能有语法错误。当您看到 FAILED 时,服务器从未启动。
  • 该命令返回Syntax OK。我也不完全明白说服务器从未启动是什么意思。即使收到FAILED 消息后,我仍然可以访问我的网站。
  • @CalebMcDaniel 也许我的 apache 生锈了,我认为它要么全部出现,要么什么都没有 :(。出于好奇,为什么要代理端口,为什么不只做标准虚拟主机,然后全部运行不在同一个端口?
  • @Collin:Gitit 在指定端口上启动自己的 Web 服务器,所以我需要两个独立的端口来拥有不同的 Gitit 实例。

标签: linux virtualhost apache


【解决方案1】:

这是你需要做的。

    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>

【讨论】:

  • 谢谢,这是一个有用的回复。事实证明,主要错误是我的发行版将日志文件存储在 /var/log/httpd 而不是 /var/log/apache2 中,因此 Apache 每次到达 ErrorLog 行时都会窒息,因为目录没有存在。直到我去尝试查看错误日志并找不到它,我才弄清楚这一点! 掌心
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2014-01-22
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 2013-09-07
    • 2016-10-06
    • 2012-01-22
    • 2019-05-31
    相关资源
    最近更新 更多