nginx站點目錄及文件URL訪問控制
阿新 • • 發佈:2018-09-03
test stat com bash 配置 .html nginx配置 python程序 chm
一、根據擴展名限制程序和文件訪問
利用nginx配置禁止訪問上傳資源目錄下的PHP、Shell、Perl、Python程序文件。
配置nginx,禁止解析指定目錄下的指定程序。
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; }
對上述目錄的限制必須卸載nginx處理PHP服務配置的前面,如下:
放置在server標簽內: server { listen 80; server_name www.dmtest.com; location / { root html; index index.php index.html index.htm; } 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; } ...... ...... }
nginx站點目錄及文件URL訪問控制