Phanix
Phanix

Just writing

Apache 2.4 ProxyPass

ProxyPass can transfer URL A to URL B, and keep the URL as URL A.

A common usage might be something like

  1. Originally there was a website site-a.com, but a new version of the website was made later, but the old forum function (www.site-a.com/forum/) should be kept
  2. Originally there are site-a.com and site-b.com, but in fact, the things under a certain path (/path1) are exactly the same, but I want users of site-a.com and site-b.com to look the same On the original website, and do not want to repeat the deploy on the two servers

In the first case, the lazy way is to move the old website to another port (such as site-a.com:8008/ ), and then use www.site-a.com/forum/ as proxy pass to www.site-a.com:8008/forum/ .
In the second case, you may put /path1/ on site-a.com, but in fact site-b.com/path1/ is also proxy pass to site-a.com/path1/

The example config file is as follows:

 $ more /etc/apache2/sites-enabled/site-a.conf
<VirtualHost *:80>
	ServerName www.site-a.com
	ServerAlias site-a.com
		
	ProxyPass /path1/ http://www.site-b.com/path1/
	ProxyPassReverse /path1/ http://www.site-b.com/path1/
</VirtualHost>

Using proxy pass and redirect is not the same. If you use redirect, then the requests after that are all to the server after the redirect, but for proxy, there will be requests on both sides (see below)

 $ tail -f /var/log/apache2/access.log
35.xxx.xxx.xxx - - [25/Jul/2017:14:57:43 +0800] "GET /path1/ HTTP/1.1" 200 1251 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv :54.0) Gecko/20100101 Firefox/54.0"
130.xxx.xxx.xxx - - [25/Jul/2017:14:57:43 +0800] "GET /path1/ HTTP/1.1" 200 1251 "-

Original link: Phanix's Blog

CC BY-NC-ND 2.0

Like my work?
Don't forget to support or like, so I know you are with me..

Loading...

Comment