我想要匹配nginx中的确切位置,如果该位置有额外的文本或参数,它应该显示一个404页面。例如,http://localhost:8080/yes
不应该显示索引页面,而应该显示404页面。这是我的.conf
文件
root /var/www/assets/;
index index.html;
location / {
default_type text/html;
try_files $uri $uri/ /index.html =404;
}
location /data {
default_type text/html;
try_files $uri $uri/ /data.html =404;
}
location /voice {
default_type text/html;
try_files $uri $uri/ /voice.html =404;
}
例如,我只想匹配/data
,不匹配/dataaa
或/datas
,如果位置不匹配上述位置,则显示404页面。
发布于 2019-02-24 16:29:40
如果您想要与/data
完全匹配,则需要使用=
指定您的位置,如下所示
location = /data {
default_type text/html;
try_files $uri $uri/ /data.html =404;
}
定义“
=/”的位置将加快这些请求的处理速度,因为搜索在第一个比较之后立即终止。
(强调我的)
https://stackoverflow.com/questions/54852457
复制