6月11日任务Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理

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;     } }

相关文章
相关标签/搜索