nginx转发请求400/404/502的问题
参考
https://blog.csdn.net/weixin_30603633/article/details/96511402?spm=1001.2014.3001.5506
https://blog.csdn.net/RRie1/article/details/115691709?spm=1001.2014.3001.5506
https://blog.csdn.net/hithedy/article/details/86693393?spm=1001.2014.3001.5506
以上参考和我问题都不一致,更不是所谓的请求头太大导致。
个人配置文件如下:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://127.0.0.1:3001/;
# 若容器不开放3001端口,使用本机ip报错404,需使用127.0.0.1/0.0.0.0才可以访问;
# 若容器开放3001端口,使用本机ip/127.0.0.1/0.0.0.0都可以访问
}
error_page 404 /404.html;
location = /40x.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 3001;
server_name localhost;
client_max_body_size 10000m;
location / {
proxy_pass http://192.x.x.92:9992/;
# 正向代理为uwsgi时使用uwsgi_pass ip:port好使
# 正向代理为tomcat时使用proxy_pass http://ip:port好使,使用uwsgi_pass报错400(遇到的坑)
}
error_page 404 /404.html;
location = /40x.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
踩上述坑的原因:
照搬配置和代码,没有理解proxy_pass和uwsgi_pass的原理。proxy使用的是http协议,uwsgi使用的是uwsgi协议,所以tomcat搭配proxy_pass,uwsgi搭配uwsgi_pass。
正向代理(web服务器):tomcat,uwsgi
反向代理:nginx
个人总结:
重新创建docker容器时,要清理缓存、容器、网络docker system prune -f --volumes,并更换容器名防止缓存
个人排查思路:
最开始是访问不到前端html静态界面-location中添加try_files $uri $uri/ /index.html;->
502-conf文件内容格式缩进问题->
404-0.0.0.0改成192.168.120.31->
400-更改uwsgi_pass为prox_pass转发->
200