[root@wjh2 ~]# vi /usr/local/nginx/conf/vhosts/discuz.conf #打开虚拟主机配置文件#php
加入如下配置:nginx
#配置防盗链vim
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$curl
{socket
valid_referers none blocked server_names *.123.com *.456.com *.google.com;php-fpm
# 对这些域名的网站不进行盗链,加入白名单。测试
if ($invalid_referer)网站
return 403;url
#显示403没法访问#
# rewrite ^/ http://www.example.com/nophoto.gif;
#跳转到某张图片显示#
}
}
curl测试结果:
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;
}
• fastcgi_pass 用来指定php-fpm监听的地址或者socket
nginx代理
背景:
好比某个地区不能访问腾讯www.qq.com,咱们能够经过其余能访问腾讯的地区作代理,来达到访问。
查询腾讯域名解析的ip地址
# vim /usr/local/nginx/conf/vhosts/proxy.conf
加入以下内容:
server {
listen 80;
server_name www.qq.com;
location / {
proxy_pass http://111.30.132.101/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}