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

CSS3 text animation effects

Effect html <div class="sp-container"...

How to use jsonp in vue

Table of contents 1. Introduction 2. Installation...

Detailed description of component-based front-end development process

Background <br />Students who work on the fr...

How is a SQL statement executed in MySQL?

Table of contents 1. Analysis of MySQL architectu...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

Introduction to the use of base link tag base

<br />When you click the link, the web page ...

Invalid solution when defining multiple class attributes in HTML

In the process of writing HTML, we often define mu...

The connection between JavaScript and TypeScript

Table of contents 1. What is JavaScript? 2. What ...

Guide to using env in vue cli

Table of contents Preface Introduction-Official E...

How to upgrade CentOS7 to CentOS8 (detailed steps)

This article uses a specific example to introduce...

How to write a Node.JS version of a game

Table of contents Overview Build Process Related ...

Tutorial diagram of installing TomCat in Windows 10

Install TomCat on Windows This article will intro...