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

How to start tomcat using jsvc (run as a normal user)

Introduction to jsvc In production, Tomcat should...

MySQL sequence AUTO_INCREMENT detailed explanation and example code

MySQL sequence AUTO_INCREMENT detailed explanatio...

vue-element-admin global loading waiting

Recent requirements: Global loading, all interfac...

Awk command line or script that helps you sort text files (recommended)

Awk is a powerful tool that can perform some task...

How to split data in MySQL table and database

Table of contents 1. Vertical (longitudinal) slic...

Non-standard implementation code for MySQL UPDATE statement

Today I will introduce to you a difference betwee...

Why MySQL does not recommend deleting data

Table of contents Preface InnoDB storage architec...

How to manage docker through UI

Docker is being used in more and more scenarios. ...

How to implement import and export mysql database commands under linux

1. Export the database using the mysqldump comman...

HTML fixed title column, title header table specific implementation code

Copy code The code is as follows: <!DOCTYPE ht...

Solution for Nginx installation without generating sbin directory

Error description: 1. After installing Nginx (1.1...

How to use Vue3 to achieve a magnifying glass effect example

Table of contents Preface 1. The significance of ...

js to achieve drag and drop sorting details

Table of contents 1. Introduction 2. Implementati...

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

MySQL Installer 8.0.21 installation tutorial with pictures and text

1. Reason I just needed to reinstall MySQL on a n...