Home > Article > Backend Development > Nginx anti-hotlink and Nginx access control and Nginx parsing php configuration
This article mainly introduces relevant information about Nginx anti-leeching and Nginx access control and Nginx parsing PHP configuration. Here are examples to help you learn and understand this part of the content. Friends in need can refer to it
Detailed explanation of the configuration of Nginx anti-hotlinking, Nginx access control and Nginx parsing php
Nginx anti-hotlinking
The configuration is as follows, which can be compared with the above configuration Combined
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; }
Nginx access control
Requirements: Only certain users are allowed to access the /admin/ directory. IP access.
Configure as follows:
location /admin/ { allow 192.168.133.1; allow 127.0.0.1; deny all; }
Create test
mkdir /data/wwwroot/test.com/admin/ echo “test,test”>/data/wwwroot/test.com/admin/1.html
Detect restart
/usr/local/nginx/bin/nginx -t && -s reload
Test
curl -x127.0.0.1:80 test.com/admin/1.html -I curl -x192.168.133.130:80 test.com/admin/1.html -I
Nginx Access Control
Configuration is as follows:
location ~ .*(abc|image)/.*\.php$ { deny all; }
According to user_agent restriction
if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato') { return 403; }
deny all and Return 403 has the same effect
Nginx parsing php configuration
The configuration is as follows:
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 is used to specify the address or socket that php-fpm monitors
Related recommendations:
Add the requested response log to the nginx log
The above is the detailed content of Nginx anti-hotlink and Nginx access control and Nginx parsing php configuration. For more information, please follow other related articles on the PHP Chinese website!