问题
Consider two urls:
- www.mysite.com/*
- www.mysite.com/browse/*
The backend runs at http://localhost:8080
How can I make sure that all requests with following pattern will end up at my backend like below?
Example:
www.mysite.com/doA --> localhost:8080/doA
www.mysite.com/browse/doA --> localhost:8080/doA
So basically both www.mysite.com/doA and www.mysite.com/browse/doA result in the same thing.
I want to use apache server. I can redirect one using proxy_http. But it doesn't work for two or more urls:
This is my config that work for one url
<VirtualHost *:80>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ProxyRequests Off
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
回答1:
This should work:
<VirtualHost *:80>
ServerName example.com
ProxyRequests Off
ProxyPass /browse/ http://localhost:8080/
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
The configured
ProxyPass
andProxyPassMatch
rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflictingProxyPass
rules starting with the longest URLs first. Otherwise, later rules for longer URLS will be hidden by any earlier rule which uses a leading substring of the URL
来源:https://stackoverflow.com/questions/38793447/how-to-route-two-different-paths-to-the-same-server-using-apache