Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx Rewrite related functions

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

# 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 "}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report