qcloud
V2EX  ›  问与答

请教一个 nginx404 错误跳转的问题

  •  
  •   qcloud · Jun 28, 2016 · 1180 views
    This topic created in 3665 days ago, the information mentioned may be changed or developed.
    配置了一个 nginx404 错误跳转到自定义 404 的页面,我是配置跳转到了一个网站,但是配置好之后, 404 并不能跳转到配置的 404 网站,而是无限重定向。。。
    http://yun.redhatcn.cn/201606289551465025547.png ( nginx 的 conf 配置)
    http://yun.redhatcn.cn/201606289595567895227.png (无限重定向)
    4 replies    2016-06-28 11:05:34 +08:00
    lhbc
        1
    lhbc  
       Jun 28, 2016   ❤️ 1
    error_page 404 =301 http://example.com/notfound.html;

    另外, 404 跳转到其他域名,你确定找不到页面就直接把用户赶走?
    qcloud
        2
    qcloud  
    OP
       Jun 28, 2016
    @lhbc 不是,我的为了截图故意搞得, V2 是全球第二大 DDCC 论坛,哈哈哈
    lhbc
        3
    lhbc  
       Jun 28, 2016   ❤️ 2
    可以用以下指令
    error_page 404 http://example.com/forbidden.html;
    error_page 404 =301 http://example.com/notfound.html;
    =后面可以用 301, 302, 303, 307

    这样做,会产生一次跳转,非常不友好


    最优雅的做法是这样
    location / {
    error_page 404 = @fallback;
    }

    location @fallback {
    proxy_pass http://backend;
    }

    或者
    error_page 404 /404.html;

    location /404.html {
    internal;
    }

    参考:
    http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
    qcloud
        4
    qcloud  
    OP
       Jun 28, 2016
    @lhbc 非常感谢,按照你得方法已经成功了,谢谢了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2899 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:52 · PVG 21:52 · LAX 06:52 · JFK 09:52
    ♥ Do have faith in what you're doing.