繁体   English   中英

如何配置Nginx错误页面跳转到其他网站?

[英]How to configure Nginx error pages to jump to another website?

我为我的网站配置了 Nginx 反向代理服务器。 我不希望用户看到 404 或 500 错误页面,因此我尝试将.conf 配置为在触发错误页面时跳转到我的网站。 我搜索了许多解决方案,但不确定我的配置是否有效,因为我不知道如何测试它。 羞愧。 任何专业人士都可以看看我的配置并提出建议吗?

我不知道如何准确地为 Nginx 配置使用“位置”。

    ....
    fastcgi_intercept_errors on;
    ....
    error_page 404 http://mywebsite.com;
        location = http://mywebsite.com {
    }

    error_page 500 502 503 504 https://mywebsite.com;

        location = https://mywebsite.com {
    }

In addition, I want the error_pages to also trigger another HTML page at the same time so that I can add a php email notification in the HTML. 这意味着当触发错误页面时,我可以收到 email。 如何配置 Nginx?

非常感谢。 狮子座

所有错误都可能触发 PHP email 通知脚本,并且 PHP 页面将执行重定向。

server {
  error_page 500 /error.php;

  location /test-error-page {
    return 500;
  }
  ...
}
<?php
  // sendEmailNotification(...)

  // redirect to new page
  header("Location: https://mywebsite.com", true, 302);

Curl 可用于从命令行测试和检查Location重定向 header:

$ curl -I https://example.com/test-error-page

HTTP/2 302 
location: https://mywebsite.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM