How to use nginx to intercept specified URL requests through regular expressions

How to use nginx to intercept specified URL requests through regular expressions

nginx server

nginx is an excellent web server that is very efficient in processing static files. At the same time, its proxy forwarding function is also very simple and efficient when combined with other background servers.

location

We know that nginx will parse the request and then get information about the requested URL. We only need to match the URL and then intercept it.

Matching rules

location / {
  if ($request_uri ~* ^/\?http(.*)$) {
         return 404;
     }
  }

After such matching, we can intercept all requests to the root directory URL and the parameter is ?httpxxx. Similar requests will display 404.

Anti-hotlink

Returns the http code, for example, to set up nginx anti-hotlinking:

location ~* \.(gif|jpg|png|swf|flv)$ {
  valid_referers none blocked www.80shihua.com www.menghuiguli.com;
  if ($invalid_referer) {
    return 404;
  }
}

nginx common variables

nginx parses out many variables that we commonly use. We just need to use them. The following are the commonly used variables of nginx. For specific usage, please refer to the official documentation.

$content_length

$content_type

$cookie_

$date_gmt

$date_local

$document_root

$document_uri

$fastcgi_path_info

$fastcgi_script_name

$gzip_ratio

$host

$hostname (ngx_http_core_module)

$hostname (ngx_stream_core_module)

$http2

$http_

$protocol

$proxy_host

$proxy_port

$query_string

$realpath_root

$request

$request_body

$request_uri

$scheme

$server_name

$uri

Summarize

This is the end of this article on how to use nginx to intercept specified URL requests through regular expressions. For more relevant content about nginx intercepting specified URL requests through regular expressions, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use nginx to block a specified interface (URL)
  • Nginx dynamically forwards to upstream according to the path in the URL
  • Practical experience of implementing nginx to forward requests based on URL
  • Introduction to the difference between adding or not adding / after the URL in nginx proxy_pass reverse proxy configuration
  • Solution to the problem of not being able to use Chinese URLs under Nginx
  • Detailed explanation of nginx configuration URL redirection-reverse proxy
  • Detailed explanation of nginx rewrite and location according to URL parameters
  • How to set up URL link in Nginx server

<<:  Vue3+script setup+ts+Vite+Volar project

>>:  How to completely delete the MySQL 8.0 service under Linux

Recommend

Five ways to traverse objects in javascript Example code

Table of contents Prepare Five weapons for…in Obj...

Summary of 3 ways to lazy load vue-router

Not using lazy loading import Vue from 'vue&#...

How to use docker to deploy Django technology stack project

With the popularity and maturity of Docker, it ha...

Vue implements custom "modal pop-up window" component example code

Table of contents Preface Rendering Example Code ...

Vue3 list interface data display details

Table of contents 1. List interface display examp...

my.cnf parameter configuration to optimize InnoDB engine performance

I have read countless my.cnf configurations on th...

Tips for implementing list loop scrolling based on jQuery (super simple)

I saw a good idea and recorded it. I have used jQ...

Fixed table width table-layout: fixed

In order to make the table fill the screen (the re...

MySQL 5.6 zip package installation tutorial detailed

Previously, we all used files with the suffix .ms...

Defining the minimum height of the inline element span

The span tag is often used when making HTML web p...

10 Website Usability Tips Everyone Should Know

Let’s not waste any more time and get straight to...

Example of adding music video to HTML page

1. Video tag Supports automatic playback in Firef...

How to build gitlab on centos6

Preface The original project was placed on the pu...

Installation and configuration tutorial of MySQL 8.0.16 under Win10

1. Unzip MySQL 8.0.16 The dada folder and my.ini ...

How does Vue3's dynamic components work?

Table of contents 1. Component Registration 1.1 G...