简体   繁体   English

apache mutile主机反向代理重写

[英]apache mutile host reverse proxy rewrite

I would like to have apache acting as reverse proxy and redirect URLs to different Host. 我想让Apache充当反向代理并将URL重定向到其他主机。

<VirtualHost *:80>
ProxyPreserveHost On
RewriteEngine       On
RewriteRule         ^/app1/(.*) http://192.168.56.102:10001/$1 [P,L]
ProxyPassReverse    /app1/ http://192.168.56.102:10001/

RewriteRule         ^/(.*) http://192.168.56.102:82/$1 [P,L]
ProxyPassReverse    / http://192.168.56.102:82
ServerName servername.local
</VirtualHost>

The code above work well and redirect my URL : 上面的代码运行良好,并重定向了我的URL:

  • servername.local to port 82 servername.local到端口82
  • servername.local/app1/ to the port 10001 servername.local / app1 /到端口10001

I would like to have also the servername.local/app1 to redirect to port 10001 but this doesn't work I have to add the / add the end of the URL I tried to add 我还希望将servername.local / app1重定向到端口10001,但这不起作用,我必须添加/添加我尝试添加的URL的末尾

 ProxyPassReverse    /app1 http://192.168.56.102:10001/

But it doesn't work is there a way to achieve that ? 但是,没有办法实现这一目标吗?

Scrap your rewrites and just use ProxyPass. 取消您的重写,仅使用ProxyPass。 You're confusing what ProxyPassReverse does with what ProxyPass or RewriteRule with the P flag does. 您将ProxyPassReverse的功能与带有P标志的ProxyPass或RewriteRule的功能混淆了。

Also, you're not "redirecting" you're proxying. 另外,您不是在“重定向”您正在代理的。 If you want to proxy /app1 then don't include the trailing slash when you setup your rewriterule or proxypass for it. 如果要代理/ app1,则在为其设置重写器或proxypass时不要在其后加上斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM