标签:Nginx防盗链 Nginx访问控制 Nginx解析php相关配置 Nginx代理
一、Nginx防盗链vim /usr/local/nginx/conf/vhost/test.com.conf
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ //location后面的*是忽略大小写
{
expires 7d;
valid_referers none blocked server_names *.test.com ; //白名单
if ($invalid_referer) {
return 403;
}
access_log off;
}
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
echo ‘121332132‘ >> /data/wwwroot/test.com/2.jpg
curl -x127.0.0.1:80 test.com/2.jpg -I
curl -e "http://www.baidu.com" -x127.0.0.1:80 test.com/2.jpg -I
vim /usr/local/nginx/conf/vhost/test.com.conf
location /admin/
{
allow 192.168.127.1;
allow 127.0.0.1;
deny all;
}
mkdir /data/wwwroot/test.com/admin/
echo “test,test”>/data/wwwroot/test.com/admin/1.html
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl -x127.0.0.1:80 test.com/admin/1.html -I
curl -x192.168.1.111:80 test.com/admin/1.html -I
location ~ .*(upload|image)/.*\.php$
{
deny all;
}
mkdir /data/wwwroot/test.com/upload
echo 12321 > /data/wwwroot/test.com/upload/1.php
curl -x127.0.0.1:80 test.com/upload/1.php
echo 12321 > /data/wwwroot/test.com/upload/1.txt
curl -x127.0.0.1:80 test.com/upload/1.txt
if ($http_user_agent ~ ‘Spider/3.0|YoudaoBot|Tomato‘)
{
return 403;
}
deny all和return 403效果一样
curl -x127.0.0.1:80 test.com -I
curl -A ‘Tomato‘ -x127.0.0.1:80 test.com -I
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 127.0.0.1 这种格式
vim /data/wwwroot/test.com/example.php
写入
<?php
phpinfo();
curl -x127.0.0.1:80 test.com/example.php
cd /usr/local/nginx/conf/vhost
dig www.baidu.com //查找一个网站的ip
如果dig命令不存在
yum install -y bind*
curl -x127.0.0.1:80 www.baidu.com/robots.txt
vim proxy.conf //加入如下内容
server
{
listen 80;
server_name www.baidu.com;
location /
{
proxy_pass http://61.135.169.121/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl -x127.0.0.1:80 www.baidu.com/robots.txt
49.Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理
标签:Nginx防盗链 Nginx访问控制 Nginx解析php相关配置 Nginx代理
原文地址:http://blog.51cto.com/13569831/2108378