Nginx Anti-theft chain
Edit a virtual host configuration file
vim /usr/local/nginx/conf/vhost/test.com.conf
Add the following in the configuration file
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;}
After changing the configuration file, you need to check the configuration file and reload
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
To test, forge a referer to access the picture, show 403
curl -e "http://www.baidu.com/1.txt"; -x192.168.71.131:80 -I test.com/1.gif
http/1.1 403 Forbidden
Nginx access Control
Access control for a directory
Edit a virtual host configuration file
vim /usr/local/nginx/conf/vhost/test.com.conf
Add the following in the configuration file
location /admin/ { allow 192.168.71.131; allow 192.168.71.132; deny all; }
Only allow 192.168.71.131 and 192.168.71.132 two IP access, all other Deny
Test, use 192.168.71.133 display 403, use 192.168.71.131 to successfully access
curl -x192.168.71.133:80 test.com/admin
curl -x192.168.71.131:80 test.com/admin
Use regular matching for access control, and deny when matching PHP-related operations to upload or image
location ~ .*(upload|image)/.*\.php$ { deny all; }
Restrictions according to User_agent
if ($http_user_agent ~ ‘Spider/3.0|baidu|qq‘) { return 403; }
Nginx parsing PHP related configuration
Edit a virtual host configuration file
vim /usr/local/nginx/conf/vhost/test.com.conf
Add the following in the configuration file
Location ~. php$
{
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/php-fcgi.sock;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/wwwroot/test.com$fastcgi_script_name;
}
Fastcgi_pass used to specify the address or socket of the PHP-FPM listener
Fastcgi_index index.php set access to the root directory by default to find the file
Fastcgi_param Script_filename/data/wwwroot/test.com$fastcgi_script_name; Set the file to be searched by default when accessing the root directory
Nginx Agent
Edit a virtual host configuration file
vim /usr/local/nginx/conf/vhost/proxy.conf
Add the following in the configuration file
server{ listen 80; server_name ask.apelearn.com; location / { proxy_pass http://121.201.9.155/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}
Nginx anti-theft chain, access control, parsing PHP-related configuration, nginx Agent