简体   繁体   中英

apache mutile host reverse proxy rewrite

I would like to have apache acting as reverse proxy and redirect URLs to different Host.

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

  • servername.local to port 82
  • servername.local/app1/ to the port 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

 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. You're confusing what ProxyPassReverse does with what ProxyPass or RewriteRule with the P flag does.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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