mod_proxy映射http:// myserver /游戏到http:// localhost:5732 /?

N00b的问题。 我有一个url

http://myserver.com/game 

并想调用内部资源

  http://localhost:5732/ 

我试过了:

 AllowCONNECT 5732 ProxyPass /game/ http://localhost:5732/ nocanon ProxyPassReverse /game/ http://localhost:5732/ 

但回来的HTML包含的链接没有得到/游戏/ prepended和JS和CSS中断。 所以我试了一下:

  RewriteEngine On RewriteRule ^/game(.*) http://localhost:5732$1 

但是发送redirect(当然不起作用)到浏览器。

我错了什么? 我的目标是:

  http://myserver/game --> http://localhost:5732/ 

非常感谢帮助

如果你的Apache版本足够新(2.4+),你可以尝试mod_proxy_html

 ProxyPass /game http://localhost:5732 nocanon ProxyPassReverse /game http://localhost:5732 <Location /game/> ProxyHTMLEnable On ProxyHTMLURLMap / /game/ </Location> 

对于旧版本的Apache,你可以试试mod_substitute 。 但是,这需要您手动编写正则expression式。 这可能是一个起点:

 ProxyPass /game http://localhost:5732 nocanon ProxyPassReverse /game http://localhost:5732 <Location /game/> SetOutputFilter SUBSTITUTE Substitute s|href='/|href='/game/|nq Substitute s|src='/|src='/game/|nq </Location> 

当然,确切的configuration将取决于您当前从游戏服务器获得的输出。

使用ProxyPass和ProxyPassReverse所做的第一个版本是执行所需操作的最常见方法。 问题是,无论你在localhost:5732上运行的是创build将被发回的HTML的东西 – 它不知道它不叫做localhost:5732。 您的代理通行证不会更改通过的页面,所以如果您的游戏包含所有错误的链接,那么您将看到。

所以,为了使这个工作,你需要重新configuration你的游戏thingy,所以它知道把它的链接等作为your.server /游戏而不是localhost.5732。