nginx 配置后网站图片加载出来一半或者不出来

项目进行nginx反向代理后发现图片和js、css等加载很慢,甚至加载不出来。

然后查看nginx的log,发现错误如下:

2023/08/29 17:15:11 [crit] 25439#0: *18 open() "/usr/local/nginx/proxy_temp/5/00/0000000005" failed (13: Permission denied) while reading upstream, client: 172.01.26.369, server: gitlab.abcdefg.com, request: "GET /assets/webpack/main.22cb49d4.chunk.js HTTP/1.1", upstream: "http://172.01.26.356:55963/assets/webpack/main.22cb49d4.chunk.js", host: "gitlab.abcdefg.com", referrer: "http://gitlab.abcdefg.com/"
2023/08/29 17:15:19 [crit] 25439#0: *13 open() "/usr/local/nginx/proxy_temp/6/00/0000000006" failed (13: Permission denied) while reading upstream, client: 172.01.26.369, server: gitlab.abcdefg.com, request: "GET /assets/application-a0c92bafde7d93e87af3bc2797125cba613018240a9f5305ff949be8a1b16528.css HTTP/1.1", upstream: "http://172.01.26.356:55963/assets/application-a0c92bafde7d93e87af3bc2797125cba613018240a9f5305ff949be8a1b16528.css", host: "gitlab.abcdefg.com", referrer: "http://gitlab.abcdefg.com/"
2023/08/29 17:15:19 [crit] 25439#0: *21 open() "/usr/local/nginx/proxy_temp/7/00/0000000007" failed (13: Permission denied) while reading upstream, client: 172.01.26.369, server: gitlab.abcdefg.com, request: "GET /assets/webpack/main.22cb49d4.chunk.js HTTP/1.1", upstream: "http://172.01.26.356:55963/assets/webpack/main.22cb49d4.chunk.js", host: "gitlab.abcdefg.com", referrer: "http://gitlab.abcdefg.com/"

 红色字体部分是主要错误信息,根据该段提示,可从中推断:

nginx没有权限访问/usr/local/nginx/proxy_temp/这个目录。

解决方案:

在nginx.conf配置文件顶部去掉#注释,并将nobody替换为root

原文 #user nobody; 换为user root;

指定root用户,这样nginx就有权限访问/usr/local/nginx/proxy_temp/目录了。

再让nginx重新加载一下配置文件后,访问就正常了。


 

你可能感兴趣的:(nginx,运维)