This article tests whether the location match ends with 1. Basic configuration of Nginx location1.1 Nginx configuration fileupstream test1{ server 127.0.0.1:8000; } upstream test2{ server 127.0.0.1:8000; } server{ server_name test.com; listen 80; access_log /usr/local/openresty/nginx/logs/test.com_access.log latest; error_log /usr/local/openresty/nginx/logs/test.com.log error; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 3s; proxy_read_timeout 120s; proxy_send_timeout 120s; proxy_next_upstream error timeout invalid_header http_404 http_502 http_504 http_500; location /user/ { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1/; } location / { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test2/; } } 1.2 Python scriptpython2 can run This script is used to obtain the request content. This serves as the backend, which is the backend of the proxy_pass proxy. #!/usr/bin/env python import SimpleHTTPServer import SocketServer PORT = 8000 class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): print(self.headers) self.send_response(200, "") def do_POST(self): print(self.headers) content_length = self.headers.getheaders('content-length') length = int(content_length[0]) if content_length else 0 print(self.rfile.read(length)) self.send_response(200, "") Handler = GetHandler httpd = SocketServer.TCPServer(("", PORT), Handler) httpd.serve_forever() 2. Testing2.1、Test location There is The nginx configuration is as follows location /user/ { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1/; } Request URL Backend content What is printed: Host: test1 Content-Length: 0 User-Agent: PostmanRuntime/7.26.8 Accept: */* Postman-Token: f2bfe770-4f44-4ee9-91c4-060f59dfb26c Accept-Encoding: gzip, deflate, br 127.0.0.1 - - [10/Apr/2021 16:54:26] "POST /test.html HTTP/1.1" 200 - Conclusion: If 2.2. Test location There is The nginx configuration is as follows location /user/ { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1; } Request URL Backend content What is printed:
Conclusion: If the proxy_pass address does not have 2.3. Test three locations No trailing The nginx configuration is as follows location /user { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1; } Request URL Backend content What is printed:
Request 2.4, location not added The last The nginx configuration is as follows location /user { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1/; } Request URL Backend content What is printed:
Request 2.5. Location end There is a The nginx configuration is as follows location /user/ { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1/haha/; } Request URL Backend content What is printed:
Request 2.6. End of location There is a The nginx configuration is as follows location /user/ { proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://test1/haha; } Request URL Backend content What is printed:
Request Conclusion |
Serial number | Access URL | Location configuration | proxy_pass configuration | Requests received by the backend | Remark |
---|---|---|---|---|---|
1 | test.com/user/test.html | /user/ | http://test1/ | /test.html | |
2 | test.com/user/test.html | /user/ | http://test1 | /user/test.html | |
3 | test.com/user/test.html | /user | http://test1 | /user/test.html | |
4 | test.com/user/test.html | /user | http://test1/ | //test.html | |
5 | test.com/user/test.html | /user/ | http://test1/haha/ | /haha/test.html | |
6 | test.com/user/test.html | /user/ | http://test1/haha | /hahatest.html |
In daily web site deployment, nginx
's proxy_pass
reverse proxy is often used. There is a configuration that needs to be clarified: when configuring proxy_pass
,
/
appears after upstram_name
, it is equivalent to the absolute root path, and nginx
will not proxy the path part matched in location
;/
, the matching path part will also be proxied.This is the end of this article about the detailed configuration of Nginx location and proxy_pass path. For more relevant Nginx location and proxy_pass path configuration content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!
<<: How to embed other web pages in a web page using iframe
>>: 25 CSS frameworks, tools, software and templates shared
<html> <head> <meta http-equiv=&quo...
Nginx can use the limit_req_zone directive of the...
1. Record several methods of centering the box: 1...
Table of contents 1. How are structures stored in...
Table of contents Creating HTML Pages Implement t...
The image can be saved on hub.docker.com, but the...
html4: Copy code The code is as follows: <form...
In the previous article, I introduced the detaile...
nohup Command When using Unix/Linux, we usually w...
Table of contents Preface Computed properties Int...
1. HTML part <Col span="2">Upload...
Pull the image: [mall@VM_0_7_centos ~]$ sudo dock...
First, let's talk about the in() query. It is...
HTML: Title Heading is defined by tags such as &l...
Table of contents background accomplish Supplemen...