本文主要是介绍Nginx错误502 Bad Gateway,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用Nginx配置的反向代理,浏览器访问的时候出现 “502 Bad Gateway” 错误,检查了一下后台error文件,发现有类似下面的错误
2024/02/05 14:21:00 [error] 166605#166605: *11 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /callback?code=oqzcbdgWRQLLeqruzoMZHXa43eYj9d&state=eyJyZXR1cm5UbyI6Imh0dHBzOi8vZmFuYmluLWV6bW0tc2VydmVyLTIuYXdzbWFzODEwLmV6bWF4Y2xvdWQuY29tIn0 HTTP/1.1", upstream: "http://127.0.0.1:8080/callback?code=oqzcbdgWRQLLeqruzoMZHXa43eYj9d&state=eyJyZXR1cm5UbyI6Imh0dHBzOi8vZmFuYmluLWV6bW0tc2VydmVyLTIuYXdzbWFzODEwLmV6bWF4Y2xvdWQuY29tIn0", host: "..."
其中 “upstream sent too big header while reading response header from upstream” 说明可能是nginx代理的缓冲区不够,因此需要调整一下缓冲区的配置,主要包括下面几个参数
proxy_buffer_size 1024k;
proxy_buffers 64 64k;
proxy_busy_buffers_size 1024k;
配置类似如下:
...
location / {proxy_pass http://127.0.0.1:8080;proxy_http_version 1.1;proxy_set_header Connection $connection_upgrade;proxy_set_header Upgrade $http_upgrade;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_buffer_size 1024k;proxy_buffers 64 64k;proxy_busy_buffers_size 1024k;
}
...
这篇关于Nginx错误502 Bad Gateway的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!