1. 程式人生 > >Linux centos VMware Nginx防盜鏈、Nginx訪問控制、Nginx解析php相關配置、Nginx代理

Linux centos VMware Nginx防盜鏈、Nginx訪問控制、Nginx解析php相關配置、Nginx代理

jpeg htm dao bubuko youdao dir cal fastcgi real-ip

一、Nginx防盜鏈

配置如下,可以和上面的配置結合起來

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訪問,配置如下:

location /admin/

{

allow 192.168.1.1101;

allow 127.0.0.1;

deny all;

}

技術分享圖片

mkdir /data/wwwroot/test.com/davery/

echo “test,test”>/data/wwwroot/test.com/davery/1.html

-t && -s reload

curl -x127.0.0.1:80 test.com/davery/1.html -I

curl -x192.168.133.130:80 test.com/davery/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相關配置

配置如下:

vim /usr/local/nginx/conf/vhost/test.com.conf

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

技術分享圖片

[root@davery ~]# vi /data/wwwroot/test.com/3,php

技術分享圖片

技術分享圖片

四、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;

}

}

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

Linux centos VMware Nginx防盜鏈、Nginx訪問控制、Nginx解析php相關配置、Nginx代理