【问题标题】:Apache Port Proxy阿帕奇端口代理
【发布时间】:2010-11-12 20:08:40
【问题描述】:

我有一个非 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/

但这不起作用。

【问题讨论】:

  • 在 ServerFault 上你可能会有更好的运气。

标签: apache2 apache-config


【解决方案1】:

代理通行证 * http://www.example.com:8001/

star 只在一个块中有效。正斜杠就是你想要的。

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

【讨论】:

  • 如果您收到内部服务器错误:sudo a2enmod proxysudo a2enmod proxy_httpsudo service apache2 restart
  • 我们不应该在 stackoverflow 上使用 mysite.com,请参阅 meta.stackexchange.com/questions/208963/…
【解决方案2】:

我在端口 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

【讨论】:

    【解决方案3】:

    完整的代码如下所示。

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

    这个link 也很有帮助。

    【讨论】:

    • 信息链接很棒,但在您的答案中提供网站的详细信息更容易获得。
    猜你喜欢
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 2014-03-15
    • 2011-02-25
    相关资源
    最近更新 更多