這篇文章主要介紹了詳解Nginx防盜鍊和Nginx存取控制與Nginx解析php的配置的相關資料,這裡提供實例幫助大家,學習理解這部分內容,需要的朋友可以參考下
#詳解Nginx防盜鍊與Nginx存取控制與Nginx解析php的設定
#Nginx防盜鏈
設定如下,可以與上面的設定結合起來
1 2 3 4 5 6 7 8 9 | 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存取.
設定如下:
##
1 2 3 4 5 6 | location /admin/
{
allow 192.168.133.1;
allow 127.0.0.1;
deny all;
}
|
登入後複製
#建立測試
1 2 | mkdir /data/wwwroot/test.com/admin/
echo “test,test”>/data/wwwroot/test.com/admin/1.html
|
登入後複製
偵測重啟
1 | /usr/local/nginx/bin/nginx -t && -s reload
|
登入後複製
測試
#
1 2 | 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存取控制
#配置如下:
1 2 3 4 | location ~ .*(abc|image)/.*\.php$
{
deny all;
}
|
登入後複製
根據user_agent限制
1 2 3 4 | if ( $http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato')
{
return 403;
}
|
登入後複製
deny all和return 403效果一樣
Nginx解析php的設定
#設定如下:
##
1 2 3 4 5 6 7 | 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日誌中新增要求的response日誌
#
以上是Nginx防盜鍊與Nginx存取控制與Nginx解析php的配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!