Configure the mod_proxy reverse proxy method in the Nginx server

  • 2020-05-09 19:56:51
  • OfStack

The reverse proxy method can be used to make the website more secure. For example, some Banks must use the reverse proxy method. Even if you enter the proxy server, you will not get any data.

Because the project needs to realize the function of 1 domain name agent
Such as:

a.com/a.html=>b.com/b.html

That is to say, a.com was used to proxy the request of b.com website. After being introduced by a friend, the reverse proxy of apache could realize its purpose.

(note that the following only introduces the reverse proxy, the forward proxy will be introduced when I use it)

1. Start the mod_proxy module of apache.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Note mod_proxy_http. so. I did not add this module when I was testing

2. Implement the proxy statement

ProxyPass /mirror/foo/ http://backend.example.com/

The implementation distributes all requests under the current host /mirror/foo/ directory to backend.example.com.
According to my request:
Add one to the a.com folder

ProxyPass / http://b.com/

1 cut ok

3. After the domain name agent:
3.1: it is better to use relative path for url in the website. If you use absolute path, it is easy to bypass the proxy, and the host behind the proxy server is easy to be exposed.
3.2: note that you are getting the current server_name domain name by referring to the $s 59en [' s 60en_name '] global variable. If you want to get the proxy domain name, you have to get the proxy domain name by $s 64en [' s 65en_X_FORWARDED_FOR ']


Related articles: