V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
miniyao
V2EX  ›  NGINX

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

  •  
  •   miniyao · 2019-12-21 16:23:22 +08:00 · 2584 次点击
    这是一个创建于 1579 天前的主题,其中的信息可能已经有所发展或是发生改变。

    下面这样写的话,出现 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;
    }
    
    }
    
    3 条回复    2019-12-21 16:57:22 +08:00
    Hyseen
        1
    Hyseen  
       2019-12-21 16:43:28 +08:00   ❤️ 1
    ```
    location / {
    try_files $uri $uri/ /index.html;
    }
    ```
    withoutxx
        2
    withoutxx  
       2019-12-21 16:45:53 +08:00 via iPhone
    搜索 nginx spa
    KuroNekoFan
        3
    KuroNekoFan  
       2019-12-21 16:57:22 +08:00
    try_files index.html =404;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5043 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:40 · PVG 13:40 · LAX 22:40 · JFK 01:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.