nginx转发请求400/404/502的问题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值