Nginx anti-theft chain, access control, parsing PHP-related configuration and Nginx Agent

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.