iis服务器助手广告广告
返回顶部
首页 > 资讯 > 服务器 >nginx 自定义403返回页面
  • 684
分享到

nginx 自定义403返回页面

nginx服务器运维 2023-08-19 07:08:08 684人浏览 安东尼
摘要

背景 因公司内部域名通常用白名单的方式来进行域名访问限制,想要自定义 403 返回页面 配置 开启允许 Nginx 使用 error_page 处理错误信息 fastcgi_intercept_errors on; 因为只涉及 nginx

背景

因公司内部域名通常用白名单的方式来进行域名访问限制,想要自定义 403 返回页面

配置

开启允许 Nginx 使用 error_page 处理错误信息

fastcgi_intercept_errors on;

因为只涉及 nginx ip 白名单,所以只需要开启 fastcgi_intercept_errors 即可,如果需要自定义 上游/代理 服务器的状态吗,则需要开启 proxy_intercept_errors
2、关于 error_page 配置

error_page 403 /403.html 可显示自定义403页面内容,正常返回403状态码。error_page 403 = /403.html 可显示自定义403页面内容,但返回200状态码。

ssi 配置
开启 ssi 配置就可以在 html 文件中使用 nginx 中的自有变量
以下配置就可以展示 nginx 中的 $remote_addr 变量

具体配置
也可以配置成返回固定的 html 文件

fastcgi_intercept_errors on;error_page 403 /custom_403.html; #自定义错误页面 urilocation = /custom_403.html {    ssi on;  # 使html支持读取变量    ssi_silent_errors on;  # 默认值是off,开启后在处理SSI文件出错时不输出错误提示    add_header Content-Type 'text/html';    add_header X-Frame-Options 'SAMEORIGIN';    return 403 '403 Forbidden

403 Forbidden

Sorry for the inconvenience.
Please report this message and include the following infORMation to us.
Thank you very much!

URL:://
Server:AMS_PROXY
Your Ip:
Date:

Powered by Tengine
tengine
';}

来源地址:https://blog.csdn.net/weixin_45066823/article/details/130008102

--结束END--

本文标题: nginx 自定义403返回页面

本文链接: https://www.lsjlt.com/news/375132.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作