12.13 Nginx防盜鏈php
修改配置文件服務器
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
expires 7d;
valid_referers none blocked server_names *.abc.com ;
if ($invalid_referer) {
return 403;
}
access_log off;
}curl
測試: ide
curl -e "http://www.abc.com/" -x127.0.0.1:80 -I abc.com/1.jpg測試
12.14 Nginx訪問控制url
修改配置文件 spa
#按目錄匹配代理
location /
{
allow 127.0.0.1;
deny all;
}server
#能夠匹配正則ip
location ~ .*(upload|image)/.*\.php$
{
deny all;
}
#根據user_agent限制
if ($http_user_agent ~* 'Spider/3.0|YoudaoBot|Tomato') //匹配符號後面+* 忽略大小寫
{
return 403;
}
deny all和return 403效果同樣
12.15 Nginx解析php相關配置
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 配置對應的參數 是sock 仍是 ip 不然502錯誤
listen.mode = 666 監聽sock 不定義mode sock文件權限440
12.16 Nginx代理
1. 新建配置文件 proxy.conf
server { listen 80; server_name 111.com; //本機域名 location / { proxy_pass http://106.39.167.118:80/; //目標服務器 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }