【问题标题】:How can I get a custom 503 error page to show up in AppHarbor如何在 AppHarbor 中显示自定义 503 错误页面
【发布时间】:2013-06-04 05:03:00
【问题描述】:

我刚刚为我的 Appharbor Web 应用程序设置了“维护”模式。通过设置配置变量,站点会将用户重定向到自定义的“停机维护”页面。我希望这个页面以 HTTP 503 状态返回,因此该站点在关闭时不会被索引。我正在像这样在操作中设置响应代码:

public ActionResult Maintenance()
{
    Response.StatusCode = 503;
    return View();
}

这一切都在我的本地服务器上按我想要的方式工作。我得到了带有 503 状态码的自定义视图。但是,一旦我部署到 AppHarbor,我就会得到一个普通的 nginx 503 错误页面。似乎 nginx 可能正在拦截响应并返回自己的错误。关于如何让自定义主体与 503 状态一起显示的任何想法?这是我看到的原始响应:

HTTP/1.1 503 Service Unavailable
Server: nginx
Date: Fri, 07 Jun 2013 19:26:09 GMT
Content-Type: text/html
Content-Length: 27
Connection: keep-alive
Cache-Control: private

The service is unavailable.

【问题讨论】:

    标签: asp.net asp.net-mvc nginx appharbor


    【解决方案1】:

    The service is unavailable. 消息实际上是 IIS 的默认 HTTP 503 消息。问题是IIS(不是nginx)默认拦截并重写响应。

    您可以通过在web.config 中使用httpErrors 元素来配置此行为,如下所示:

    <system.webServer>
        <httpErrors existingResponse="PassThrough"></httpErrors>
    </system.webServer>
    

    请注意,配置此项可能会对您的应用程序产生安全影响。你可以阅读更多关于配置httpErrorsin this article

    【讨论】:

      猜你喜欢
      • 2011-06-07
      • 2014-05-14
      • 2013-02-13
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多