學習四十六
12.13 Nginx防盜鏈
12.14 Nginx訪問控制
12.15 Nginx解析php相關配置
12.16 Nginx代理
擴展
502問題匯總 http://ask.apelearn.com/question/9109
location優先級 http://blog.lishiming.net/?p=100
Nginx防盜鏈
配置如下,可以和上面的配置結合起來
location ~ ^.+.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
expires 7d;
valid_referers none blocked server_names
if ($invalid_referer) {
return 403;
}
access_log off;
}
Nginx訪問控制
需求:訪問/admin/目錄的請求,只允許某幾個IP訪問,配置如下:
location /admin/
{
allow 192.168.1.33;
allow 127.0.0.1;
deny all;
}
mkdir /data/wwwroot/test.com/admin/
echo “test,test”>/data/wwwroot/test.com/admin/1.html
-t && -s reload
curl -x127.0.0.1:80 test.com/admin/1.html -I
可以匹配正則
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;
#此處要與前面配置的scok文件一致,
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}
如果報錯502
檢查制定的sock文件路徑
fastcgi_pass 用來指定php-fpm監聽的地址或者socke
此處還要檢查文件權限是不是666
Nginx代理
cd /usr/local/nginx/conf/vhost
vim proxy.conf //加入如下內容
server
{
listen 80;
server_name ask.apelearn.com;
location /
{
proxy_pass http://121.201.9.155/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
curl ask.apelean.com/robots.txt
#
#robots.txt for MiWen#
User-agent: *
Disallow: /?/admin/
Disallow: /?/people/
Disallow: /?/question/
Disallow: /account/
Disallow: /app/
Disallow: /cache/
Disallow: /install/
Disallow: /models/
Disallow: /crond/run/
Disallow: /search/
Disallow: /static/
Disallow: /setting/
Disallow: /system/
Disallow: /tmp/
Disallow: /themes/
Disallow: /uploads/
Disallow: /url-*
Disallow: /views/
學習四十六