想把所有 URL 请求,都跳到一个指定文件,不要 url 带参数就出 404 错误,里面这个的配置怎么写才行?

2019-12-21 16:23:22 +08:00
 miniyao

下面这样写的话,出现 sample.com/abc 就会因为 /abc 不存在,出 404 错误。想把 URL 请求里的所有参数都忽略。

server {
listen 443 ssl;
server_name sample.com;

ssl on;
ssl_certificate /etc/ssl/sample.com.pem;
ssl_certificate_key /etc/ssl/sample.com.key;
ssl_prefer_server_ciphers on;

access_log off;
error_log off;

location / {
    root /usr/local/nginx/html;
    index  index.html index.htm;
}

}
2590 次点击
所在节点    NGINX
3 条回复
Hyseen
2019-12-21 16:43:28 +08:00
```
location / {
try_files $uri $uri/ /index.html;
}
```
withoutxx
2019-12-21 16:45:53 +08:00
搜索 nginx spa
KuroNekoFan
2019-12-21 16:57:22 +08:00
try_files index.html =404;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/631086

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX