V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
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 · Dec 21, 2019 · 3068 views
    This topic created in 2321 days ago, the information mentioned may be changed or developed.

    下面这样写的话,出现 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 replies    2019-12-21 16:57:22 +08:00
    Hyseen
        1
    Hyseen  
       Dec 21, 2019   ❤️ 1
    ```
    location / {
    try_files $uri $uri/ /index.html;
    }
    ```
    withoutxx
        2
    withoutxx  
       Dec 21, 2019 via iPhone
    搜索 nginx spa
    KuroNekoFan
        3
    KuroNekoFan  
       Dec 21, 2019
    try_files index.html =404;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   984 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    ♥ Do have faith in what you're doing.