網站首頁 編程語言 正文
前言
Nginx 默認是不允許列出整個目錄的。
如需此功能,打開?nginx.conf
?文件或你要啟用目錄瀏覽虛擬主機的配置文件,在?location server
?或?http
?段中加入
autoindex on;
另外兩個參數最好也加上去:
autoindex_exact_size off;
默認為?on
,顯示出文件的確切大小,單位是 bytes。
改為?off
?后,顯示出文件的大概大小,單位是 KB 或者 MB 或者 GB
autoindex_localtime on;
默認為?off
?,顯示的文件時間為 GMT 時間。
改為?on
?后,顯示的文件時間為文件的服務器時間。
第一種:autoindex 配置
一級目錄或整個虛擬主機開啟目錄流量
在?nginx.conf
?文件 中?server
?段添加
location / { autoindex on; autoindex_localtime on; #之類的參數寫這里 }
單獨目錄開啟目錄流量
二級目錄開啟目錄流量
location /down/ { autoindex on; }
虛擬目錄開啟目錄流量
location /down/ { alias /home/wwwroot/test/; autoindex on; }
第二種:nginx location 配置
一、禁止訪問某些后綴文件
location ~ \.(ini|conf|txt)$ { deny all; }
二、禁止訪問目錄或目錄下文件
#禁止訪問目錄 location ^~ /test/ { deny all; }
#禁止訪問目錄下文件 location ^~ /test { deny all; }
三、禁止訪問某個目錄下的指定文件后綴文件
# 禁止訪問某個目錄下的 php 后綴文件 location /directory { location ~ .*\.(php)?$ { deny all; } }
# 禁止訪問多個目錄下的 php 后綴文件 location ~* ^/(directory1|directory2)/.*\.(php)${ deny all; }
四、nginx location 匹配相關
-
=
?表示精確匹配 -
^~
?表示 uri 以某個字符串開頭 -
~
?正則匹配(區分大小寫) -
~*
?正則匹配(不區分大小寫) !和!*分別為區分大小寫不匹配及不區分大小寫不匹配的正則 -
/
?任何請求都會匹配 - 匹配優先級:?
= > ^~ > /
五、nginx 配置圖片直接下載不打開
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { add_header Content-Disposition attachment; }
原文鏈接:https://www.cnblogs.com/niuben/p/16844745.html
相關推薦
- 2022-08-31 在.Net?Framework應用中請求HTTP2站點的問題解析_實用技巧
- 2022-03-31 用python實現彈球小游戲_python
- 2022-08-18 Android?Canva實現漸變進度條_Android
- 2023-01-02 C語言中getchar(?)?函數使用詳解_C 語言
- 2022-07-16 Electron項目中的NSIS配置項
- 2022-12-14 Jetpack?Compose?DropdownMenu手指跟隨點擊顯示_Android
- 2022-04-30 LINQ投影操作符Select與限制操作符where介紹_C#教程
- 2022-09-22 求解器選擇與收斂性問題(OR-Tools)
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支