惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cisco Talos Blog
Cisco Talos Blog
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
The Exploit Database - CXSecurity.com
T
Tor Project blog
T
Threat Research - Cisco Blogs
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Hacker News
The Hacker News
A
Arctic Wolf
J
Java Code Geeks
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
博客园 - 叶小钗
L
LINUX DO - 热门话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cloudbric
Cloudbric
Forbes - Security
Forbes - Security
博客园 - 【当耐特】
博客园_首页
L
Lohrmann on Cybersecurity
T
Threatpost
Schneier on Security
Schneier on Security
博客园 - 司徒正美
The Cloudflare Blog
腾讯CDC

博客园 - 散尽浮华

Rancher 证书到期问题处理手册 Rancher部署并导入K8S集群 K8S集群灾备环境部署 K8S容器环境下GitLab-CI和GItLab Runner 部署记录 K8S持久化存储PV、PVC笔记 K8S部署ES集群 - 运维笔记 容器和镜像转化、迁移方式 - 运维小结 K8S部署RabbitMQ集群 (镜像模式) - 部署笔记 Pod滚动重启方法 - 运维笔记 Node节点禁止调度(平滑维护)方式- cordon,drain,delete K8S中NodePort端口范围修改 Centos7.4升级到Centos7.7 K8S部署Redis Cluster集群(三主三从模式) - 部署笔记 K8S部署Nacos集群 - 部署笔记 K8S部署Kafka界面管理工具(kafkamanager) K8S部署Kafka集群 - 部署笔记 K8S部署RocketMQ集群(双主双从+同步模式) - 部署笔记 Nginx流量拷贝 - 运维笔记 Nginx禁止ip访问或非法域名访问 - 配置笔记
Nginx基于站点目录和文件的URL访问控制 - 配置笔记
散尽浮华 · 2020-11-18 · via 博客园 - 散尽浮华

对于为用户服务的大多数公司而言,把控用户权限是一件十分重要的事情。通过配置Nginx来禁止访问上传资源目录下的PHP、shell、Python等程序文件,这样用户即使上传了这些文件也没法去执行,以此来加强网站安全。

1. 限制禁止解析指定目录下的制定程序

location ~ ^/images/.*.(php|php5|.sh|.pl|.py)$ { 
  deny all; 
} 

location ~ ^/static/.*.(php|php5|.sh|.pl|.py)$ { 
  deny all; 
} 

location ~* ^/data/(attachment|avatar)/.*.(php|php5)$ { 
  deny all; 
} 

2. 禁止访问Nginx的root根目录下的某些文件

location ~*.(txt|doc)${
  if (-f $request_filename) {
    root /data/www/www;
    #还可以使用"rewrite ...."重定向某个URL
    break;
  }
}

location ~*.(txt|doc)${
    root /data/www/www;
    deny all;
}

需要注意:如果有php匹配配置,上面的限制配置应该放在php匹配的前面

location ~.*.(php|php5)?${
  fastcgi_pass 127.0.0.1:9000
  fastcgi_index index.php
  include fcgi.conf;
}

3. 禁止指定目录或path匹配的访问

location ~ ^/(static)/ {
        deny all;
}

location ~ ^/static {
        deny all;
}


#禁止访问目录并返回指定的http状态码
location /admin/ { 
  return 404; 
}
location /templates/ { 
  return 403; 
}

4. 限制网站来源IP访问。比如禁止某目录让外界访问,但允许某IP访问该目

location ~ ^/order/ { 
  allow 172.16.60.23; 
  deny all;
}

还可以使用if来限制客户端ip访问(即添加白名单限制)

if ( $remote_addr = 172.16.60.28 ) {
    return 403;
}

if ( $remote_addr = 172.16.60.32 ) {
    set $allow_access_root 'true';
}