When using nginx as a reverse proxy, you can simply forward the request to the next service intact. Setting the proxy_pass request will only replace the domain name. If you want to access different services based on different URL suffixes, you need to use the following method: Method 1: Add "/"server { listen 8000; server_name abc.com; access_log "pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G" main; location ^~/user/ { 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_set_header X-NginX-Proxy true; proxy_pass http://user/; } location ^~/order/ { 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_set_header X-NginX-Proxy true; proxy_pass http://order/; } } ^~/user/ means matching requests with the prefix user . If proxy_pass ends with / , the path after /user/* will be directly concatenated to the end, that is, user will be removed. Method 2: rewriteupstream user server localhost:8089 weight=5; } upstream order server localhost:8090 weight=5; } server { listen 80; server_name abc.com; access_log "pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G" main; location ^~/user/ { 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_set_header X-NginX-Proxy true; rewrite ^/user/(.*)$ /$1 break; proxy_pass http://user; } location ^~/order/ { 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_set_header X-NginX-Proxy true; rewrite ^/order/(.*)$ /$1 break; proxy_pass http://order; } } There is no / at the end of proxy_pass , and rewrite rewrites the URL. --------------------- The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Solution to forgetting the MYSQL database password under MAC
>>: Understanding what Node.js is is so easy
Table of contents Preface Is the interviewer aski...
If Ubuntu is the most popular Linux operating sys...
Usually the pictures uploaded by users need to be...
This article example shares the specific code of ...
CSS controls the printing style of web pages : Use...
1. Install dependency packages [root@localhost ~]...
Table of contents 1. Deconstruction Tips 2. Digit...
Table of contents Preface Function Overloading Ma...
ContentsHyperledger fabric1.4 environment setup u...
Take the deployment of https://gitee.com/tengge1/...
A simple license plate input component (vue) for ...
background There is a requirement in the project ...
I have been studying how to get https. Recently I...
This article shares the specific code of Vue to a...
This article example shares the specific code of ...