当前我的配置文件(/ etc / nginx / sites-available / default)显示
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location /credentials.js {
deny all;
return 404;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
,但是我仍然可以通过网络上的example.com/credentials.js访问certificate.js。有什么建议么?
答案 0 :(得分:0)
尝试将=
添加到您的位置,这将完全匹配:
server {
server_name _;
listen 80 default_server;
location = /credentials.js {
deny all;
return 404;
}
location / {
add_header Content-Type text/plain;
return 200 "hello world\n\n";
}
}
如果找到完全匹配的内容,搜索将终止。例如,如果“ /”请求频繁发生,则定义“ location = /”将加快这些请求的处理速度,因为搜索将在第一次比较后立即终止。这样的位置显然不能包含嵌套的位置。