nginx 404 跳转到自定义的页面

1. 自己写了一个error.html页面


2. 更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on;


3. 更改nginx.conf中在server 区域加入: error_page 404  /404.html 


4. 重启ngnix


另外,有一个8000端口的错误页面也要跳转到80的error页面,

在server 8000下添加 error_page 404 error, 另外 include error.conf


# the difference when adding URI to proxy_pass directive:
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

# why I use variable but not staticlly config the url:
# http://forum.nginx.org/read.php?2,215830,215832#msg-215832
#
# and resolver is needed, or will get 502, ref:
# https://stackoverflow.com/questions/5743609/
#
# why use rewrite: http://wiki.nginx.org/HttpProxyModule#proxy_pass

resolver 127.0.0.1;

location /error {
    proxy_pass  http://127.0.0.1:80;
}

location /images {
    proxy_pass  http://127.0.0.1:80;
}

location /js {
    proxy_pass  http://127.0.0.1:80;
}

location /css {
    proxy_pass  http://127.0.0.1:80;
}


### 解决 Nginx 1.22 中 `ssl_renegotiation_limit` 报错及自定义 403 页面问题 #### 关于 `ssl_renegotiation_limit` 报错 Nginx 1.22 不支持 `ssl_renegotiation_limit` 指令,这是因为在开源版本中,该指令尚未被引入。根据已有资料[^2],类似的高级 SSL 功能通常只存在于较新的版本或商业版 Nginx Plus 中。因此,当尝试在配置文件中使用此指令时,会出现 `unknown directive` 错误。 为了缓解这一问题,可以通过以下方法替代: 1. **升级 Nginx 到更新版本** 如果可能的话,建议将 Nginx 升级到至少 1.25 或更高版本。新版本可能会提供更多关于 SSL 的增强功能和支持更多的安全参数。 2. **调整 OpenSSL 配置** 在编译 Nginx 时指定最新的 OpenSSL 版本,并通过优化 SSL/TLS 设置来减少不必要的重协商需求。例如: ```bash ./configure --with-http_ssl_module --with-openssl=/path/to/openssl-source ``` 3. **禁用不必要功能** 若不需要频繁的 SSL 重协商,则可以在配置中明确限制某些行为。例如,启用 SNI(Server Name Indication)验证以防止非法连接: ```nginx ssl_reject_handshake on; ``` 此外,还可以通过设置更强的加密套件和协议来提高安全性并降低重协商的可能性。 #### 自定义 403 Forbidden 页面实现 对于自定义 403 错误页面的需求,Nginx 提供了灵活的方式来进行配置。具体步骤如下: 1. 创建一个 HTML 文件作为自定义的 403 页面内容。假设保存为 `/usr/share/nginx/html/custom_403.html`。 2. 修改 Nginx 配置文件,在对应的 `server` 块中加入以下内容: ```nginx error_page 403 /custom_403.html; location = /custom_403.html { root /usr/share/nginx/html; internal; # 确保外部无法直接访问错误页 } ``` 3. 测试配置有效性并重新加载服务: ```bash nginx -t nginx -s reload ``` 这样即可完成对 403 错误页面的定制化处理[^3]。 --- ### 注意事项 - 当前环境下的 Nginx 版本决定了可用的功能范围,请务必确认所使用的版本号及其特性支持情况。 - 对于生产环境而言,任何改动都应经过充分测试后再上线实施,以免影响正常业务运作。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值