【问题标题】:HTTP headers and error pages - NGINXHTTP 标头和错误页面 - NGINX
【发布时间】:2018-04-05 03:59:17
【问题描述】:

我在使用 NGINX 中的自定义错误页面时遇到了一些问题。 首先,我尝试了这个

server {
    ...
    location / {
        if ( $request_method !~ (GET|POST) ) {
            error_page 418 = @not_supported;
            return 418;
        }
        proxy_pass http://x.x.x.x;
    }

    location @not_supported {
        return 501;
    }

    error_page 501 /some_page.html;
    location = /some_page.html {
        root html;
    }
}

如果我发送除GETPOST 以外的任何其他内容,我会收到一个显示501 method is not implemented 的默认错误页面,以及服务器的名称和版本。 如果返回在第一个位置,则服务器返回some_page.html

在那之后,我尝试添加recursive_error_pages,这确实帮助我提供了自定义错误页面,但它完全改变了标题(添加了我之前删除的标题)。

有人知道如何让服务器为自定义页面提供服务,并保留标题的设置吗?

谢谢。

【问题讨论】:

  • 你能用例子清楚地说明你想要什么吗?

标签: linux nginx server http-headers webserver


【解决方案1】:

我设法解决了。 我将所有我想要的配置移动到错误的位置,它就像一个魅力。

【讨论】:

    猜你喜欢
    • 2013-01-25
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2019-11-25
    • 2016-04-16
    相关资源
    最近更新 更多