詳解Nginx防盜鏈和Nginx訪問控制與Nginx解析php的配置
Nginx防盜鏈
配置如下,可以和上面的配置結合起來
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訪問控制
需求:訪問/admin/目錄的請求,只允許某幾個IP訪問.
配置如下:
location /admin/{ allow 192.168.133.1; allow 127.0.0.1; deny all;}
創建測試
mkdir /data/wwwroot/test.com/admin/echo “test,test”>/data/wwwroot/test.com/admin/1.html
檢測重啟
/usr/local/nginx/bin/nginx -t && -s reload
測試
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訪問控制
配置如下:
location ~ .*(abc|image)/.*/.php${ deny all;}
根據user_agent限制
if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato'){ return 403;}
deny all和return 403效果一樣
Nginx解析php的配置
配置如下:
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 用來指定php-fpm監聽的地址或者socket
以上就是Nginx防盜鏈和Nginx訪問控制與Nginx解析php的配置的講解,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答