Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use nginx to regularly intercept specified url requests

Shulou Source: shulou.com Published: 2022-06-02 11:59:45 10月09日 Update

This article mainly explains the method of using nginx to regularly intercept specified url requests, the content is clear, interested partners can learn, I believe it will be helpful after reading.

Nginx server

Nginx is an excellent web server, which is very efficient in dealing with static files, and its proxy forwarding function is very simple and efficient with other back-end servers.

Location

We know that nginx will parse the request and get the url and other information about the request. We just need to match the url and intercept it.

Matching rule

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

After such a match, we can intercept all the URLs of the request root directory and similar requests with a parameter of? httpxxx will display 404.

Hotlink protection

Return http code, such as setting nginx hotlink protection:

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 a lot of variables that we often use, and we just need to take them over and use them. Here are the variables commonly used by nginx. For specific usage, you can 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

After reading the above, do you have a better understanding of the method of using nginx to regularly intercept specified url requests? if you want to learn more, you are welcome to follow the industry information channel.

Tags: Method content variable commonly used server service regular learning anti-theft code usage information interest function parameter at the same time background official for this boy. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux Docker OPPO Reno Redmi