小编典典

Apache重定向到另一个端口

all

我已经为此苦苦挣扎了一段时间,并且肯定做错了什么。

我在同一台机器上有 Apache 服务器和 JBoss 服务器。我想将流量重定向mydomain.example到 JBoss
localhost:8080/example。当前已设置 DNS,mydomain.example当输入浏览器时,它将直接转到端口 80。

我的问题是,当某个域名进入 Apache(在本例中为mydomain.example)时,我如何重定向到不同的端口?

<VirtualHost ip.addr.is.here>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName mydomain.example
  ProxyPass http://mydomain.example http://localhost:8080/example
  ProxyPassReverse http://mydomain.example http://localhost:8080/example
</VirtualHost>

实施一些建议后:


阅读 43

收藏
2022-08-15

共1个答案

小编典典

您应该http://example.com在 ProxyPass 和 ProxyPassReverse 中省略域并将其保留为/.
此外,您需要将/末尾的保留example/到重定向的位置。http://example.com此外,我在使用vs.时遇到了一些麻烦http://www.example.com——只有
www 才起作用,直到我将 ServerName www.example.com 和 ServerAlias example.com 设置为。试一试。

<VirtualHost *:80> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName www.example.com
  ServerAlias example.com
  ProxyPass / http://localhost:8080/example/
  ProxyPassReverse / http://localhost:8080/example/
</VirtualHost>

进行这些更改后,添加所需的模块并重新启动 apache

sudo a2enmod proxy && sudo a2enmod proxy_http && sudo service apache2 restart
2022-08-15