Nginx 报错百科:502、504、413、403 等常见错误原因与解决方法
Nginx 常见报错的原因、排查命令和修复配置:502、504、499、413、403、404、405、400 Cookie 过大、PHP File not found、重定向过多、SSL 握手失败、端口占用、权限错误等。
502Nginx 502 Bad Gateway 原因与解决方法
502 表示 Nginx 连不上或读不懂后端(PHP-FPM、Node、Docker 容器等)。按「后端是否在跑 → 地址端口是否一致 → 权限/SELinux → 响应头过大」的… 504Nginx 504 Gateway Timeout 原因与解决方法
504 表示后端在 Nginx 的等待时间内没有返回。先找出慢在哪里(慢查询、外部接口、队列),再按需调大 proxy_read_timeout 或 fastcgi_read_ti… 413Nginx 413 Request Entity Too Large 上传文件太大
413 是请求体超过了 client_max_body_size(默认只有 1MB)。在 http、server 或 location 中调大即可,PHP 站点还要同步改 uplo… 403Nginx 403 Forbidden 原因与解决方法
403 通常是目录没有 index 文件、文件权限不让 nginx 读、deny 规则命中,或 SELinux 拦截。看 error.log 里是 “directory index… 404Nginx 404 与 try_files:伪静态、SPA 路由、root/alias 写法
文件明明在却 404,多半是 root/alias 拼出来的路径不对,或 WordPress、Vue/React 路由没有用 try_files 回退到入口文件。… 3xx重定向次数过多(ERR_TOO_MANY_REDIRECTS)的 Nginx 解决方法
浏览器提示「重定向次数过多」,最常见的是 CDN 用 HTTP 回源、源站又把 HTTP 跳到 HTTPS,形成死循环;其次是 www 和裸域互相跳、应用和 nginx 各跳一次。… SSLNginx SSL 握手失败(SSL handshake failed)排查
SSL 握手失败多见于:证书没用 fullchain、证书和私钥不匹配、443 没写 ssl 参数、协议/加密套件太旧或太新,以及 CDN 回源时 SNI 不匹配。… bindNginx 启动失败:98: Address already in use(端口被占用)
80/443 端口已经被别的程序占了(Apache、Caddy、宝塔、Docker 容器、另一个 nginx 实例),或配置里同一端口写了重复的 IPv6 监听。… EOFupstream prematurely closed connection 原因与解决
后端在 Nginx 还没收完响应时就把连接关了。常见于后端进程崩溃或超时自杀、keepalive 设置不一致、WebSocket 没有正确升级,以及大文件下载时后端超时。… 13Nginx (13: Permission denied) 权限错误排查
13: Permission denied 出现在读文件、连 socket、写日志或绑定端口时,原因是运行用户没有权限、父目录不可进入、socket 属主不对,或 SELinux … 400Nginx 400 Request Header Or Cookie Too Large 解决方法
400「Request Header Or Cookie Too Large」表示某一行请求头(多半是 Cookie)比 large_client_header_buffers 的… 499Nginx 499 Client Closed Request 是什么,怎么处理
499 是 nginx 自己定义的状态码,只出现在访问日志里:客户端在 nginx 回应之前就断开了。大量 499 通常说明后端太慢、前面的 CDN 或负载均衡先超时放弃了。先查慢… 500Nginx 500:rewrite or internal redirection cycle 解决方法
日志里的 “rewrite or internal redirection cycle” 表示请求在 nginx 内部反复跳转超过 10 次,最后返回 500。最常见的是 try_… 404Nginx + PHP-FPM「File not found」/ Primary script unknown
页面只显示 “File not found.”、日志里是 “Primary script unknown”,说明 PHP-FPM 按 SCRIPT_FILENAME 找不到 PHP… 502Nginx 502:upstream sent too big header 解决方法
“upstream sent too big header” 表示后端返回的响应头(通常是很多或很大的 Set-Cookie、长 Location)超过了 proxy_buffer… 502Nginx 报 no resolver defined to resolve 的原因与解决
proxy_pass 里用了变量(如 proxy_pass https://$host 或 $backend)时,域名要在请求时解析,而 nginx 不读 /etc/resolv.… emergcould not build server_names_hash 的解决方法
nginx -t 报 “could not build server_names_hash, you should increase server_names_hash_bucke… warnNginx 警告 conflicting server name … ignored 怎么处理
“conflicting server name "example.com" on 0.0.0.0:80, ignored” 表示两个 server 块在同一个地址端口上写了同一个… 405Nginx 405 Not Allowed:POST 请求被拒绝的原因
nginx 返回 405 Not Allowed,最常见的是 POST(或 PUT、DELETE)请求落到了静态文件上:静态文件只接受 GET 和 HEAD。通常是接口路径没有被 … emergNginx unknown directive 报错:http2、brotli、quic 等
nginx -t 报 “unknown directive "http2"” 之类,说明当前 nginx 不认识这个指令:要么版本太旧(http2 on 需要 1.25.1+),要… emergNginx cannot load certificate:证书文件不存在或与私钥不匹配
nginx -t 报 “cannot load certificate … No such file or directory”,最常见的是还没签证书就先写了 ssl_certif…
502 表示 Nginx 连不上或读不懂后端(PHP-FPM、Node、Docker 容器等)。按「后端是否在跑 → 地址端口是否一致 → 权限/SELinux → 响应头过大」的… 504Nginx 504 Gateway Timeout 原因与解决方法
504 表示后端在 Nginx 的等待时间内没有返回。先找出慢在哪里(慢查询、外部接口、队列),再按需调大 proxy_read_timeout 或 fastcgi_read_ti… 413Nginx 413 Request Entity Too Large 上传文件太大
413 是请求体超过了 client_max_body_size(默认只有 1MB)。在 http、server 或 location 中调大即可,PHP 站点还要同步改 uplo… 403Nginx 403 Forbidden 原因与解决方法
403 通常是目录没有 index 文件、文件权限不让 nginx 读、deny 规则命中,或 SELinux 拦截。看 error.log 里是 “directory index… 404Nginx 404 与 try_files:伪静态、SPA 路由、root/alias 写法
文件明明在却 404,多半是 root/alias 拼出来的路径不对,或 WordPress、Vue/React 路由没有用 try_files 回退到入口文件。… 3xx重定向次数过多(ERR_TOO_MANY_REDIRECTS)的 Nginx 解决方法
浏览器提示「重定向次数过多」,最常见的是 CDN 用 HTTP 回源、源站又把 HTTP 跳到 HTTPS,形成死循环;其次是 www 和裸域互相跳、应用和 nginx 各跳一次。… SSLNginx SSL 握手失败(SSL handshake failed)排查
SSL 握手失败多见于:证书没用 fullchain、证书和私钥不匹配、443 没写 ssl 参数、协议/加密套件太旧或太新,以及 CDN 回源时 SNI 不匹配。… bindNginx 启动失败:98: Address already in use(端口被占用)
80/443 端口已经被别的程序占了(Apache、Caddy、宝塔、Docker 容器、另一个 nginx 实例),或配置里同一端口写了重复的 IPv6 监听。… EOFupstream prematurely closed connection 原因与解决
后端在 Nginx 还没收完响应时就把连接关了。常见于后端进程崩溃或超时自杀、keepalive 设置不一致、WebSocket 没有正确升级,以及大文件下载时后端超时。… 13Nginx (13: Permission denied) 权限错误排查
13: Permission denied 出现在读文件、连 socket、写日志或绑定端口时,原因是运行用户没有权限、父目录不可进入、socket 属主不对,或 SELinux … 400Nginx 400 Request Header Or Cookie Too Large 解决方法
400「Request Header Or Cookie Too Large」表示某一行请求头(多半是 Cookie)比 large_client_header_buffers 的… 499Nginx 499 Client Closed Request 是什么,怎么处理
499 是 nginx 自己定义的状态码,只出现在访问日志里:客户端在 nginx 回应之前就断开了。大量 499 通常说明后端太慢、前面的 CDN 或负载均衡先超时放弃了。先查慢… 500Nginx 500:rewrite or internal redirection cycle 解决方法
日志里的 “rewrite or internal redirection cycle” 表示请求在 nginx 内部反复跳转超过 10 次,最后返回 500。最常见的是 try_… 404Nginx + PHP-FPM「File not found」/ Primary script unknown
页面只显示 “File not found.”、日志里是 “Primary script unknown”,说明 PHP-FPM 按 SCRIPT_FILENAME 找不到 PHP… 502Nginx 502:upstream sent too big header 解决方法
“upstream sent too big header” 表示后端返回的响应头(通常是很多或很大的 Set-Cookie、长 Location)超过了 proxy_buffer… 502Nginx 报 no resolver defined to resolve 的原因与解决
proxy_pass 里用了变量(如 proxy_pass https://$host 或 $backend)时,域名要在请求时解析,而 nginx 不读 /etc/resolv.… emergcould not build server_names_hash 的解决方法
nginx -t 报 “could not build server_names_hash, you should increase server_names_hash_bucke… warnNginx 警告 conflicting server name … ignored 怎么处理
“conflicting server name "example.com" on 0.0.0.0:80, ignored” 表示两个 server 块在同一个地址端口上写了同一个… 405Nginx 405 Not Allowed:POST 请求被拒绝的原因
nginx 返回 405 Not Allowed,最常见的是 POST(或 PUT、DELETE)请求落到了静态文件上:静态文件只接受 GET 和 HEAD。通常是接口路径没有被 … emergNginx unknown directive 报错:http2、brotli、quic 等
nginx -t 报 “unknown directive "http2"” 之类,说明当前 nginx 不认识这个指令:要么版本太旧(http2 on 需要 1.25.1+),要… emergNginx cannot load certificate:证书文件不存在或与私钥不匹配
nginx -t 报 “cannot load certificate … No such file or directory”,最常见的是还没签证书就先写了 ssl_certif…
服务器上一键体检:curl -fsSL nginx.cc/fix | sudo bash