分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

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

发布时间:2023-09-06 01:25责任编辑:彭小芳关键词:配置

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代理

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved