12.13 Nginx防盜鏈
12.14 Nginx訪問控制
12.15 Nginx解析php相關配置
12.16 Nginx代理php
1.Nginx防盜鏈html
示例一:nginx
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$vim
{ curl
expires 7d; socket
valid_referers none blocked server_names *.test.com ; 定義白名單 ide
if ($invalid_referer) { 若是不是白名單,返回403php-fpm
return 403; 測試
} url
access_log off;
}
2.Nginx訪問控制
示例一:
location /admin/
{
allow 192.168.133.1;
allow 127.0.0.1;
deny all;
}
示例二:禁止解析php
location ~ .*(abc|image)/.*\.php$
{
deny all;
}
示例三:根據user-agent限制
if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato')
{
return 403;
}
3.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;
}
4.Nginx代理
示例一:
server
{
listen 80;
server_name ask.apelearn.com; 定義一個域名
location /
{
proxy_pass http://121.201.9.155/; 配置真實IP
proxy_set_header Host $host; 要訪問的域名
proxy_set_header X-Real-IP $remote_addr; 指定ip的
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}