First, nginx anti-theft chain
Add the following code to the configuration file: (/usr/local/nginx/conf/vhost/test.com.conf)
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ { expires 7d; valid_referers none blocked server_names *.test.com ; if ($invalid_referer) { return 403; } access_log off;}
~ Regular, case insensitive
^ with what what switch
Expires 7d expiration time is seven days
Valid_referers None blocked Server_names . test.com;
Define a whitelist domain name
return 403; If it's not a whitelist, it will return 403 code.
Test Referer:curl-e "www.baidu.com"-x127.0.0.1:80 test.com-i
If the whitelist returns 200, not the words return 403
Second, Nginx's access control
1, requirements: Access to the/admin/directory request, only a few IP access, configured as follows: (/usr/local/nginx/conf/vhost/test.com.conf)
For the Polygon directory:
location /admin/{ allow 192.168.133.1; allow 127.0.0.1; deny all;}
Localtion Define which directory
Test:
Create file directory: Mkdir/data/wwwroot/admin
echo "Test,test" >/data/wwwroot/test.com/admin/1.html
-T &&-S reload
curl-x127.0.0.1:80 test.com-i Tip 200 Normal access
Take an IP host with more access, Tip 403.
2, match the regular, add the following content:
Prevent PHP from being parsed by uploading directories
location ~ .*(upload|image)/.*\.php${ deny all;}
Disable parsing of upload|image directory files ending in PHP
Test:
mkdir data/wwwroot/test.com/upload/1.php
echo "132323" >/data/wwwroot/test.com/upload/1.php
curl-x127.0.0.1:80 test.com/upload/1.php Tips 403
Cancel rule, normal access 200
3, root usr_agent limit (want to do a hidden site, do not let Baidu, Bing and other engine crawler crawling data)
if ($http _user_agent ~ ' spider/3.0| Youdaobot| Tomato ')
{
return 403;
}
Deny all is the same as the return 403 effect
Nginx anti-theft chain, access control, parsing PHP-related configuration and Nginx Agent