Implementation of proxy_pass for nginx Reverse Proxy

  • 2021-09-11 21:51:12
  • OfStack

The format is simple: proxy_pass URL;

Where URL includes: transport protocol (http:/, https:/, etc.), host name (domain name or IP: PORT), uri.

Examples are as follows:


proxy_pass http://www.xxx.com/;
proxy_pass http://192.168.200.101:8080/uri;
proxy_pass unix:/tmp/www.sock;

There are several situations to note for the configuration of proxy_pass:

Assume that server_name is www. xxx. com

When asked for http://www. xxx. com/aming/a. html, the results of the above sample accesses are

Example 1:


location /aming/
{
  proxy_pass http://192.168.1.10;
  ...
}

Results 1: http://192.168. 1.10/aming/a. html

Example 2:


location /aming/
{
  proxy_pass http://192.168.1.10/;
  ...
}

Results 2: http://192.168. 1.10/a. html

Example 3:


location /aming/
{
  proxy_pass http://192.168.1.10/linux/;
  ...
}

Results 3: http://192.168. 1.10/linux/a. html

Example 4:


location /aming/
{
  proxy_pass http://192.168.1.10/linux;
  ...
}

Results 4: http://192.168. 1.10/linuxa. html

Summary:

For easy memory and specification, it is recommended that all url after proxy_pass end with "/".


proxy_pass http://192.168.1.10/linux/;

Related articles: