This article mainly introduces the implementation of nginx multiple locations forwarding any request or accessing static resource files, and shares it with you. The details are as follows: server { #Listening port listen 80; #The domain name to be listened to server_name localhost; #Listen to the URL with suffix location ^~\.txt { #Put the file in the /html folder root /; } #Listen to all URLs. If there is no special requirement, just use this location. #Use wildcards to enter location only if no other locations are matched / { #Removed the restriction that only URLs are forwarded, because directly accessing the domain name will not pass if and thus the request cannot be forwarded. proxy_pass http://localhost:8080; } } With matching rules: You will understand the rules if you try them yourself. The following is the original text↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ server { #Listening port listen 80; #The domain name to be listened to server_name localhost; #Listen to the URL with suffix location ^~\.txt { #Put the file in the /html folder root /; } #Monitor all URLs. If there is no special requirement, just use this location. location / { #Requests without a suffix are forwarded in order to cooperate with the previous location to access the resource file instead of forwarding all requests. If there is no special requirement, do not judge and directly proxy_pass to the request if (!-e $request_filename){ proxy_pass http://localhost:8080; break; } } } You can add multiple locations, but be careful not to conflict with each other, otherwise forwarding multiple requests will time out. This is the end of this article about the implementation of nginx multiple locations forwarding arbitrary requests or accessing static resource files. For more relevant content about nginx location forwarding arbitrary requests, 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! You may also be interested in:
|
<<: ReactHooks batch update state and get route parameters example analysis
>>: Navicat Premium operates MySQL database (executes sql statements)
Learning objectives: The two functions parseInt()...
Table of contents 1: Encapsulation idea 2. Packag...
1. Accessing literals and local variables is the ...
1. Why create an index? (Advantages) This is beca...
What are HTTP Headers HTTP is an abbreviation of ...
The virtual machine used is CentOS 8.4, which sim...
Effect: CSS style: <style type="text/css&...
Click here to return to the 123WORDPRESS.COM HTML ...
Check whether your cuda is installed Type in the ...
We hope to insert the weather forecast into the w...
The effect is as follows: The code is as follows ...
Table of contents 1. Introduction 2. Solution Imp...
Docker installs MySQL version 8.0.20 for your ref...
Table of contents Install Importing components Ba...
Any number of statements can be encapsulated thro...