码迷,mamicode.com
首页 > Web开发 > 详细

Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理

时间:2017-11-15 17:11:07      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:lnmp架构

Nginx防盗链




1、[root@centos7 test.com]# vi /usr/local/nginx/conf/vhost/test.com.conf 

#+表示1或者多个,+前面的字符 

    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 ;

    #定义referer白名单

    if ($invalid_referer) {

        return 403;

    #if函数的意思是:如果不是白名单内的域名,返回值:403

    }

    access_log off;

}



验证:

curl -e:指定referer链接


[root@centos7 test.com]# curl -e "http://123123asdsd.test.com/asdas" -x127.0.0.1:80 -I test.com/baidu.png

HTTP/1.1 200 OK

Server: nginx/1.12.1


使用非白名单内的referer进行访问,被拒绝。


Nginx访问控制

需求:访问admin目录,只能允许几个指定IP可以访问,其他禁止

1、[root@centos7 test.com]# vim /usr/local/nginx/conf/vhost/test.com.conf 


server

{

    listen 80;

    server_name test.com  test2.com test3.com;

    index index.html index.htm index.php;

    access_log /tmp/test.com.log combined_realip;

    root /data/wwwroot/test.com;

    location /admin/

    {

    allow 192.168.3.74;

    allow 127.0.0.1;

    deny all;

    #从上至下的执行权限

    }

验证:

[root@centos7 test.com]# curl -x127.0.0.1:80  test.com/admin/admin.html

“admin root”

[root@centos7 test.com]# curl -x192.168.3.74:80  test.com/admin/admin.html

“admin root”


Nginx访问控制

可以匹配正则

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相关配置


location ~ \.php$

        #匹配以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;

            #这里的路径要和root路径一致

        }



Nginx代理


本文出自 “探索发现新事物” 博客,请务必保留此出处http://jacksoner.blog.51cto.com/5802843/1981991

Nginx防盗链、Nginx访问控制、Nginx解析php相关配置、Nginx代理

标签:lnmp架构

原文地址:http://jacksoner.blog.51cto.com/5802843/1981991

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!