[英]Nginx: Deny access of a directory and files inside it
我有一個目錄 /admin,我想阻止任何人通過 public IP 訪問該目錄和目錄中的文件。這是我的設置:
location /admin/ {
allow 192.168.0.0/24;
deny all;
}
這在訪問目錄時工作正常,但是,如果有人專門訪問目錄內的文件(例如,url =“../admin/adminer.php),它不會拒絕文件的訪問。我也試過其他設置如:
location ~ /admin/.*$ {
allow 192.168.0.0/24;
deny all;
}
當從公共 IP 訪問時,這似乎可以拒絕所有訪問,但是,當通過內部 IP 訪問時,php 代碼不再有效,php 代碼只是作為明文回顯。
此處提供了我的位置指令 rest,以防它以某種方式影響行為:
location / {
try_files $uri $uri/ /index.php?args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
希望有人能幫我解決這個問題。
server {
location ^~ /vendor/ {
deny all;
return 403;
}
...
}
創建另一個位置塊,然后查看是否可行:
location ~ /admin/.*\.php$ {
allow 192.168.0.0/24;
deny all;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.