Implementation of nginx multiple locations forwarding any request or accessing static resource files

Implementation of nginx multiple locations forwarding any request or accessing static resource files

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:
  • Detailed explanation of the mechanism and implementation of accept lock in Nginx
  • Solve the problem of Nginx returning 404 after configuring proxy_pass
  • Solution to Nginx SSL certificate configuration error
  • Nginx 502 Bad Gateway Error Causes and Solutions
  • Proxy_pass method in multiple if in nginx location
  • Nginx configuration sample code for downloading files
  • How to view nginx configuration file path and resource file path
  • Detailed explanation of the implementation of nginx process lock

<<:  ReactHooks batch update state and get route parameters example analysis

>>:  Navicat Premium operates MySQL database (executes sql statements)

Recommend

JavaScript parseInt() and Number() difference case study

Learning objectives: The two functions parseInt()...

Steps to encapsulate the carousel component in vue3.0

Table of contents 1: Encapsulation idea 2. Packag...

Detailed example of reading speed of js objects

1. Accessing literals and local variables is the ...

Understand all aspects of HTTP Headers with pictures and text

What are HTTP Headers HTTP is an abbreviation of ...

About the problem of offline installation of Docker package on CentOS 8.4

The virtual machine used is CentOS 8.4, which sim...

Markup Language - Print Style Sheets

Click here to return to the 123WORDPRESS.COM HTML ...

Win10 uses Tsinghua source to quickly install pytorch-GPU version (recommended)

Check whether your cuda is installed Type in the ...

How to insert weather forecast into your website

We hope to insert the weather forecast into the w...

Recommend a cool flashing alarm button

The effect is as follows: The code is as follows ...

Vue two fields joint verification to achieve the password modification function

Table of contents 1. Introduction 2. Solution Imp...

MySQL 8.0.20 installation and configuration tutorial under Docker

Docker installs MySQL version 8.0.20 for your ref...

How to use the markdown editor component in Vue3

Table of contents Install Importing components Ba...

JavaScript function detailed introduction

Any number of statements can be encapsulated thro...