25

我有一个非 Apache 服务器监听端口 8001 和 Apache 监听端口 80。我希望某个虚拟域实际上由非 Apache 服务器通过端口 80 提供服务。

例子:

<VirtualHost *:80>
  Servername example.com

  # Forward this on to the server on port 8001
</VirtualHost>

我想我可以用 mod_proxy 和 ProxyPass 来做到这一点。

ProxyPass * http://www.example.com:8001/

但这不起作用。

4

3 回答 3

35

ProxyPass * http://www.example.com:8001/

星号只在一个区块中有效。正斜杠是你想要的。

ProxyPass / http://www.example.com:8001/
ProxyPassReverse / http://www.example.com:8001/

反向代理可确保将端口 8001 服务器发送的重定向调整为代理的规范名称。

apache手册有一些例子。 http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

于 2009-08-10T03:25:52.233 回答
7

我在端口 80 上有一个由 apache 托管的站点。我还有一个侦听端口 8880 的 python Web 服务器,需要通过http://[mydomainname]/something访问。使用 txyoji 的回答,我通过简单地向我的虚拟主机定义添加代理传递来使其工作,如下所示:

ProxyPass /something http://mydomainname:8880/something
ProxyPassReverse /something http://mydomainname:8880/something

更新

根据您的设置,更好的方法是为“localhost”上的端口设置代理通行证。我认为你在做什么更清楚,而且更便携。除此之外,您甚至不必打开该端口的防火墙!您可以在本地代理传递到任何端口,因此如果您不需要,没有理由将其暴露给外界。通过端口 80 汇集所有内容,让 Apache 始终“排在前面”。然后,您可以担心它的安全性。

ProxyPass /something http://localhost:8880/something
ProxyPassReverse /something http://localhost:8880/something
于 2015-08-05T21:44:35.800 回答
0

完整的代码如下所示。

<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
ServerName test.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://localhost:9301/
ProxyPassReverse / http://localhost:9301/

SSLCertificateFile /etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

这个链接也有帮助。

于 2021-03-11T08:57:51.400 回答