Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx Rewrite related functions

Shulou Source: shulou.com Published: 2022-06-03 09:39:49 12月06日 Update

# nginx configuration of www.hechunping.com website [root@CentOS7-01 image] # cat / apps/nginx/conf/vhosts/www.hechunping.com.conf server {listen 80; server_name www.hechunping.com; location ~ *\. (png | jpg) ${root html/image; access_log / data/nginx/logs/www.hechunping.com/access.log access_json } [root@CentOS7-01 image] # ls / apps/nginx/html/image/aa.jpg [root@CentOS7-01 image] # cat / apps/nginx/html/hechunping/index.html hechunping web [root@CentOS7-01 image] # systemctl reload nginx# access test can be seen in the access log of the www.hechunping.com site that the access / aa.jpg is from the address "referer": "http://www.hechunping.tech [root@CentOS7-01 image" ] # tail-N1 / data/nginx/logs/www.hechunping.com/access.log {"@ timestamp": "2020-01-07T17:15:52+08:00" "host": "192.168.7.71", "clientip": "192.168.7.1", "size": 425253, "responsetime": 0.048, "upstreamtime": "", "upstreamhost": "-", "http_host": "www.hechunping.com", "uri": "/ aa.jpg", "domain": "www.hechunping.com", "xff": "-", "referer": "http://www.hechunping.tech/","tcp_xff":""," "http_user_agent": "Mozilla/5.0 (Windows NT 10.0 Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 "," status ":" 200"}

3.2 implementation of hotlink protection is based on access security considerations. Nginx allows to check whether the requested referer information is valid through the ngx_http_referer_module module. Official document: https://nginx.org/en/docs/http/ngx_http_referer_module.html#valid_referers implements hotlink protection. The definition is as follows: [root@CentOS7-01 image] # cat / apps/nginx/conf/vhosts/www.hechunping.com.conf server {listen 80 Server_name www.hechunping.com; location ~ *\. (png | jpg) ${root html/image; access_log / data/nginx/logs/www.hechunping.com/access.log access_json; valid_referers none blocked server_names * .hechunping.com api.online.test/v1/hostlist ~\ .Google. \ .Baidu\. If ($invalid_referer) {return 403 } [root@CentOS7-01 image] # ls / apps/nginx/html/image/aa.jpg [root@CentOS7-01 image] # systemctl reload nginx# access test you can see "referer" in the access log of the www.hechunping.com site: "http://www.hechunping.tech status code 403 [root@CentOS7-01 image] # tail-N1 / data/nginx/logs/www.hechunping.com/access.log {" @ timestamp ":" 2020-01-07T17:49:43+08:00 " "host": "192.168.7.71", "clientip": "192.168.7.1", "size": 548, "responsetime": 0.000, "upstreamtime": "-", "upstreamhost": "-", "http_host": "www.hechunping.com", "uri": "/ aa.jpg", "domain": "www.hechunping.com", "xff": "-", "referer": "http://www.hechunping.tech/","tcp_xff":""," "http_user_agent": "Mozilla/5.0 (Windows NT 10.0 Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 "," status ":" 403 "}

Tags: Instruction configuration condition variable domain name character status resource permanent expression test result string regular browser website path browse information address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Linux Redmi OPPO Reno