How to route two different paths to the same server using apache

混江龙づ霸主 提交于 2019-12-11 05:58:19

问题


Consider two urls:

  1. www.mysite.com/*
  2. 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 and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!