A personal summary of a pit where forwarding does not take effect after nginx configuration

I. Overview

The nginx configuration rules are still a bit complicated. Here I will only summarize a pit and a solution I encountered. The specific reason is not clear.

2. Pit that does not take effect after configuration

1. First, the sample url to be accessed is:

http://10.123.123.123:8080/b/c/getInfo
		 
http://10.123.123.123:8080/a/b/c/getMsg

The rules configured in nginx are:

        location /b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }

2. At this point, visit:

http://10.123.123.123:8080/b/c/getInfo

According to the configuration of nginx, it will be forwarded to:

http://10.124.124.124:8089/api/other_Systems/getInfo

This is no problem.

3. However, visit:

http://10.123.123.123:8080/a/b/c/getMsg

I thought it could also be forwarded to:

http://10.124.124.124:8089/api/other_Systems/getMsg

The result is not the case, the access is still http://10.123.123.123:8080/a/b/c/getMsgnot forwarded according to the rules.

3. Solutions

1.nginx needs to be configured like this:

        location /b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }
         
        location /a/b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }

In this way, we can put:

http://10.123.123.123:8080/a/b/c/getMsg

Forward to:

http://10.124.124.124:8089/api/other_Systems/getMsg

Four. Postscript

1. After modifying the nginx configuration file, to find the nginx startup file, use the command to restart: sudo ./nginx -s reload, don’t forget this.

2. Why it is not clear why only one forwarding rule can be configured, but two. The reason is not clear. Let me summarize the solution first.

Guess you like

Origin blog.csdn.net/BHSZZY/article/details/129517606