Scenario 1: Due to server restrictions, only one port is open to the outside world, but a different external network environment needs to be requested, so nginx is used on the transit server to forward the data. accomplish: server { listen 8051; server_name localhost; location /license/ { proxy_pass http://xxx.xxx.xxx.xxx:8058/; } location / { proxy_pass http://xxx.xxx.xxx.xxx:8051/; } } Special Note: Note: If the file upload forwarding is involved here, add client_max_body_size 100m under server_name; The domain name forwarding address, proxy_pass must be followed by "/", otherwise it will cause abnormal forwarding When configuring proxy_pass proxy forwarding in nginx, if you add / to the URL after proxy_pass, it means the absolute root path; Assume that the following four situations are accessed using http://192.168.1.1/proxy/aerchi.html respectively. The first one:
Proxy to URL: http://127.0.0.1/aerchi.html The second type (compared to the first type, with one less / at the end)
Proxy to URL: http://127.0.0.1/proxy/aerchi.html The third type:
Proxy to URL: http://127.0.0.1/aaa/aerchi.html The fourth type (compared to the third type, with one less / at the end)
Proxy to URL: http://127.0.0.1/aaaaerchi.html Scenario 2: Due to business needs, a set of front-end code needs to be mapped to two back-end addresses, so it is necessary to distinguish and forward on the interface, and the distinguishing mark needs to be removed during forwarding accomplish: server { listen 0.0.0.0:8204; server_name localhost; #Static page directory root E:\xxxxxxx; #Default homepage index /index.html; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_cookie_path /* /*; client_max_body_size 100m; location ~*/wx/(.*) {#Distinguish dynamic pages based on whether the interface contains /wx/# and hand them over to tomcat for processing if (!-e $request_filename) { proxy_pass http://127.0.0.1:8091/$1;#When going to the backend, you need to remove /wx} } location / { # User browser cache settings location ~* \.(css|js|jpg|jpeg|gif|png|swf|htm|html|json|xml|svg|woff|ttf|eot|map|ico)$ { expires -1; if (-f $request_filename) { break; } } # Dynamic page, handed over to tomcat for processing if (!-e $request_filename) { proxy_pass http://127.0.0.1:8092; #proxy_cookie_path /* /*; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } Special Note: 1. proxy_set_header Host $http_host; The request headers are not changed. 2. proxy_set_header Host host; if the client request header does not carry this header, the request passed to the backend server will not contain this header. In this case, host is used; if the client request header does not carry this header, then the request passed to the backend server does not contain this header either. In this case, host is used; if the client request header does not carry this header, then the request passed to the backend server does not contain this header either. In this case, the host variable is used. Its value is the value of the "Host" field when the request contains the "Host" request header, and the primary domain name of the virtual host when the request does not carry the "Host" request header; 3. proxy_set_header Host host: host:host:proxy_port; The server name can be passed along with the port of the backend server: 4. If the value of a request header is empty, then the request header will not be sent to the backend server: proxy_set_header Accept-Encoding ""; 5. The user's real IP address is forwarded to the backend server
Scenario 3: The previous code is implemented with Vue. Vue does not have a specific page and also accesses resources through /xx/xx. At this time, it needs to be distinguished from the background interface accomplish: They can be distinguished by special characters like "#". Requests with # are static resources by default. location ~* \.(#|css|js|jpg|jpeg|gif|png|swf|htm|html|json|xml|svg|woff|ttf|eot|map|ico)$ { expires -1; if (-f $request_filename) { break; } } Scenario 4: Due to server restrictions, database access requires nginx forwarding accomplish: stream { upstream cloudsocket hash $remote_addr consistent; server database actual ip:3306 weight=5 max_fails=3 fail_timeout=30s; } server { listen 127.0.0.1:8058; #Local proxy port proxy_connect_timeout 10s; proxy_timeout 300s;#Set the timeout between the client and the proxy service. If there is no operation within 5 minutes, it will be automatically disconnected. proxy_pass cloudsocket; } } Special attention: stream is at the same level as http, so don't put it in http Scenario 5: When accessing a domain name, you need to redirect to another address accomplish: server { listen 7000; server_name localhost; client_max_body_size 100m; location = / { rewrite ^(.*) https://www.baidu.com permanent; } } Special attention:
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: The difference between JS pre-parsing and variable promotion in web interview
>>: Problems and solutions encountered when connecting node to mysql database
This article shares the specific method of instal...
I recently stumbled upon the Audiovisual Linux Pr...
This article example shares the specific code of ...
1. Achieve results 2. Data format returned by the...
How does "adaptive web design" work? It’...
About CSS3 variables When declaring a variable, a...
need: Usually, sites want to prevent videos and p...
Using Technology itext.jar: Convert byte file inp...
It is difficult to find good image material websi...
One of our web projects has seen an increase in t...
First, let me talk about the general idea: 1. Log...
Our bank's MGR will be launched at the end of...
Table of contents How to represent the current ti...
Use JS to complete a simple calculator for your r...
Table of contents Preface 1. What is selenium? 2....