1、配置虚拟主机文件
[iyunv@bogon tmp]# cat /usr/local/nginx/conf/vhosts/test.conf
server
{
listen 80;
server_name www.test.com www.aaa.com ;
if ($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/ $1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log combined_realip;
location ~ .*admin\.php$ {
auth_basic "caimz auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi1.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|gz|bz2)$
{
access_log off;
expires 15d;
valid_referers none blocked *.test.com *.aaa.com *.aminglinux.com;
if ($invalid_referer)
{
return 403;
}
}
location ~ \.(js|css)
{
access_log off;
expires 2h;
}
location ~ (static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi1.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
2、检查配置文件
[iyunv@bogon tmp]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
3、重新加载nginx的配置文件
[iyunv@bogon tmp]# /usr/local/nginx/sbin/nginx -s reload
4、测试
curl -e可是测试referer
上图图片地址为:
[iyunv@bogon tmp]# curl -e "http://www.baidu.com/111" -I -x127.0.0.1:80 'http://www.test.com/static/image/common/logo_88_31.gif'
HTTP/1.1 403 Forbidden #测试也就是我这图片能否放在baidu网上。 显示403则说明防盗链设置OK,起作用了。禁止盗取。
Server: nginx/1.6.2
Date: Sun, 25 Oct 2015 09:45:30 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
[iyunv@bogon tmp]# curl -I -x127.0.0.1:80 'http://www.test.com/static/image/common/logo_88_31.gif'
HTTP/1.1 200 OK #测试也就是我这图片能否放在www.test.com 。 显示200则说明防盗链设置OK,起作用了。可以的,因为www.test.com 就是在我白名单中
Server: nginx/1.6.2
Date: Sun, 25 Oct 2015 09:45:45 GMT
Content-Type: image/gif
Content-Length: 2528
Last-Modified: Tue, 09 Jun 2015 17:21:10 GMT
Connection: keep-alive
ETag: "55772086-9e0"
Expires: Mon, 09 Nov 2015 09:45:45 GMT
Cache-Control: max-age=1296000
Accept-Ranges: bytes
[iyunv@bogon tmp]# curl -e "http://www.test.com/111" -I -x127.0.0.1:80 'http://www.test.com/static/image/common/logo_88_31.gif'
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sun, 25 Oct 2015 09:46:14 GMT
Content-Type: image/gif
Content-Length: 2528
Last-Modified: Tue, 09 Jun 2015 17:21:10 GMT
Connection: keep-alive
ETag: "55772086-9e0"
Expires: Mon, 09 Nov 2015 09:46:14 GMT
Cache-Control: max-age=1296000
Accept-Ranges: bytes
[iyunv@bogon tmp]# curl -e "http://www.aaa.com/111" -I -x127.0.0.1:80 'http://www.test.com/static/image/common/logo_88_31.gif'
HTTP/1.1 200 OK #测试也就是我这图片能否放在www.aaa.com 。 显示200则说明防盗链设置OK,起作用了。可以的,因为www.aaa.com 就是在我白名单中
Server: nginx/1.6.2
Date: Sun, 25 Oct 2015 09:46:21 GMT
Content-Type: image/gif
Content-Length: 2528
Last-Modified: Tue, 09 Jun 2015 17:21:10 GMT
Connection: keep-alive
ETag: "55772086-9e0"
Expires: Mon, 09 Nov 2015 09:46:21 GMT
Cache-Control: max-age=1296000
Accept-Ranges: bytes
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com