How to use nginx to block a specified interface (URL)

How to use nginx to block a specified interface (URL)

1. Introduction

Sometimes, after the web platform is online, you need to block a service interface, but you don’t want to go online again. You can use nginx to block the specified platform interface.

2. Specific operations

In the server node of the nginx configuration file nginx.conf, add a location. The example is as follows:

location /your url {
  return 403;
}

Here we take nginx's own nginx.conf as an example to block the root URL path /:

Before shielding

location / {
  root html;
  index index.html index.htm;
}

The results of accessing the nginx index.html page are as follows:

After shielding

location / {
  return 403;
  root html;
  index index.html index.htm;
}

The results of accessing the nginx index.html page are as follows:

After modifying the nginx.conf configuration file, you do not need to restart nginx. Instead, run the nginx -s reload command to reload the configuration file and the modified rules will take effect.

Additional knowledge: nginx blocks requests from specific http_referer

Add to the server configuration item of nginx.conf

if ($http_referer ~* "www.xxx.com") {
  return 403;
}

The above operation method of nginx blocking the specified interface (URL) is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use nginx to intercept specified URL requests through regular expressions
  • 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

<<:  Detailed explanation of the difference between v-model directive and .sync modifier in Vue

>>:  Detailed explanation of the installation and configuration process of mysql8.018 on linux

Recommend

Detailed explanation of mysql basic operation statement commands

1. Connect to MySQL Format: mysql -h host address...

How to ensure transaction characteristics of MySQL InnoDB?

Preface If someone asks you "What are the ch...

Implementation of fuzzy query like%% in MySQL

1, %: represents any 0 or more characters. It can...

Some conclusions on developing mobile websites

The mobile version of the website should at least...

mysql 8.0.15 winx64 decompression version graphic installation tutorial

Every time after installing the system, I have to...

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

Solve the problem of MySql8.0 checking transaction isolation level error

Table of contents MySql8.0 View transaction isola...

Detailed explanation of common MySQL operation commands in Linux terminal

Serve: # chkconfig --list List all system service...

Steps to set up Windows Server 2016 AD server (picture and text)

Introduction: AD is the abbreviation of Active Di...

Using docker command does not require sudo

Because the docker daemon needs to bind to the ho...

10 Best Practices for Building and Maintaining Large-Scale Vue.js Projects

Table of contents 1. Use slots to make components...

Vue2.0 implements adaptive resolution

This article shares the specific code of Vue2.0 t...

webpack -v error solution

background I want to check the webpack version, b...

CSS3 sample code to achieve element arc motion

How to use CSS to control the arc movement of ele...