nginx 500 Internal Server Error openresty 错误原因归纳

架构说明

前后端分离, nginx代理后端程序
例如下面配置:

  location /bbbbb/api/
     {
       proxy_redirect off;
       proxy_set_header Host $host:$server_port; #$server_port
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Nginx-Proxy true;
       proxy_pass http://localhost:8082/xxxxx/api/;
     }

出现 nginx 500 错误

例如下面的500 白页
在这里插入图片描述
这个一看就是nginx的500 页面,表示很有可能是后端程序出错,
但是一般后端程序,例如springboot 这种一般都有全局异常捕获(@ControllerAdvice),所以不应该出现跳转到nginx的 500 页面。

这里整理一下可能的情况:

1. 查看在异常捕获的时候,是否设置了HttpStatus

这种错误,一般nginx access_log 和 error_log 均无法看出异常信息!
例如下面的

    /**
     * 程序运行异常
     *
     * @param e Exception
     * @return ResponseVO
     */
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseVO<JSONObject> handleException(Throwable e) {
        logger.error("程序运行异常--Throwable:", e);
        String msg = i18nService.selectMsgByCode(CommonBusinessCode.SERVER_ERROR);
        CurrentUserContext.remove();
        return ResponseVO.create(ResponseVO.FAIL, msg,
                i18nService.createErrorBody(
                        CommonBusinessCode.SERVER_ERROR, e.getMessage(), e.getClass().getSimpleName()));
    }

对于全局异常捕获,没有必要再设置HttpStatus 为500,这个应该还是正常返回200,交由前端页面根据自定义的状态字段判断展示信息。

2. 其他情况均可以根据 access_log 和 error_log看出异常信息

  • 硬盘空间满了 ,df -h ll -h 命令检查
  • nginx配置文件错误 , nginx -t 命令检查
  • too many open files,修改nginx的worker_rlimit_nofile参数,使用ulimit查看系统打开文件限制,修改/etc/security/limits.conf
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值