解决nginx配置不当导致接口请求数据被截断的问题

问题

最近请求一些接口,发现浏览器端拿到的JSON返回数据被截断,前端无法解析。

分析

Java后端没有报错,一般就是反向代理的问题,Nginx配置有很大的嫌疑。

  1. 检查nginx的error_log,发现确实nginx报错:
2020/07/28 14:13:49 [crit] 113301#0: *45739 open() "/opt/work/nginx/proxy_temp/6/10/0000000106" failed (13: Permission denied) while reading upstream, client: x.x.x.y, server: x.x.x.x, request: "GET /api/some/address?startTime=1595312026524&endTime=1595916826524&timeUnit=5 HTTP/1.0", upstream: "http://x.x.x.x:8500/api/some/address?startTime=1595312026524&endTime=1595916826524&timeUnit=5", host: "api.slankka-inc.com", referrer: "http://api.slankka-inc.com/api/some/view"

查看目录权限发现:
/opt/work/nginx

drwxrwxr-x 11 hue    hue 4.0K Oct 31  2019 .
drwxrwxr-x 15 hue    hue 4.0K Aug  2  2019 ..
drwx------  2 nobody hue 4.0K Mar 21  2019 client_body_temp
drwxrwxr-x  2 hue    hue 4.0K Jun 17 09:56 conf
drwx------  2 nobody hue 4.0K Feb 19  2019 fastcgi_temp
drwxr-xr-x  2 hue    hue 4.0K Feb 19  2019 html
drwxrwxr-x  2 hue    hue 4.0K Feb 19  2019 logs
-rw-r--r--  1 hue    hue    6 Feb 19  2019 nginx.pid
drwx------ 12 nobody hue 4.0K Feb 20  2019 proxy_temp
drwxrwxr-x  2 hue    hue 4.0K Feb 19  2019 sbin
drwx------  2 nobody hue 4.0K Feb 19  2019 scgi_temp
drwx------  2 nobody hue 4.0K Feb 19  2019 uwsgi_temp

proxy_temp目录的owner是 nobody,启动进程的用户为hue。

  1. 这类问题应该比较常见,需要网上搜索查找原因
    这里选取四篇文章
    Nginx返回大长度的JSON数据被截断 这篇是解决思路
    返回值过长时被nginx截断的解决办法 这篇是Nginx没有权限的具体原因
    nginx进程属主问题讨论 这篇是用户为nobody现象的分析
    nginx的proxy_temp目录权限为nobody nginx -t操作 这篇是根本原因

解决

  1. 将目录属主全部改为 hue。 执行:chown -R hue:hue /opt/work/nginx
  2. root用户下,慎用nginx -t

猜你喜欢

转载自www.cnblogs.com/slankka/p/13391063.html