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

How to elegantly implement the mobile login and registration module in vue3

Table of contents Preface Input box component lay...

Detailed explanation of sshd service and service management commands under Linux

sshd SSH is the abbreviation of Secure Shell, whi...

Detailed explanation of MySQL database isolation level and MVCC

Table of contents 1. Isolation Level READ UNCOMMI...

js memory leak scenarios, how to monitor and analyze them in detail

Table of contents Preface What situations can cau...

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

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

How to change the CentOS server time to Beijing time

1. I purchased a VPS and CentOS system, and found...

How to display div on object without being blocked by object animation

Today I made a menu button. When you move the mous...

MySQL daily statistics report fills in 0 if there is no data on that day

1. Problem reproduction: Count the total number o...

Vue implements zip file download

This article example shares the specific code of ...

Installation tutorial of the latest stable version of MySQL 5.7.17 under Linux

Install the latest stable version of MySQL on Lin...

How to set up scheduled backup tasks in Linux centos

Implementation Preparation # Need to back up the ...

Example code for implementing a simple search engine with MySQL

Table of contents Preface Introduction ngram full...