Nginx 笔记摘要

Summary: Author: 张亚飞 | 阅读时间: 2 minute read | Published: 2016-06-11
Filed under Categories: LinuxTags: Note,

Nginx 笔记摘要


Nginx 错误

使用网址加载脚本压缩链接 https://admin.chinashan.org/ajaxLoad/minify?g=afterLoadScriptList 脚本文件未加载全,查看Nginx错误日志报如下错误:

2017/07/20 15:26:07 [crit] 18353#18353: *1 open() "/var/cache/nginx/fastcgi_temp/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 221.235.85.226, server: admin.chinashan.org, request: "GET /ajaxLoad/minify?g=afterLoadScriptList HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "admin.chinashan.org"
2017/07/20 15:28:16 [crit] 18353#18353: *1 open() "/var/cache/nginx/fastcgi_temp/2/00/0000000002" failed (13: Permission denied) while reading upstream, client: 221.235.85.226, server: admin.chinashan.org, request: "GET /ajaxLoad/minify?g=afterLoadScriptList HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "admin.chinashan.org"
2017/07/20 15:28:51 [crit] 18367#18367: *68 open() "/var/cache/nginx/fastcgi_temp/3/00/0000000003" failed (13: Permission denied) while reading upstream, client: 221.235.85.226, server: admin.chinashan.org, request: "GET /ajaxLoad/minify?g=afterLoadScriptList HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "admin.chinashan.org"

好像是 /var/cache/nginx/fastcgi_temp 没有权限错误

/var/cache/nginx

ls -al
drwxr-xr-x  7 root  root  4096 Nov 15  2016 ./
drwxr-xr-x 11 root  root  4096 Nov 16  2016 ../
drwx------  2 nginx root  4096 Jul 19 11:41 client_temp/
drwx------ 12 nginx root 4096 Nov 18  2016 fastcgi_temp/
drwx------  2 nginx root  4096 Nov 15  2016 proxy_temp/
drwx------  2 nginx root  4096 Nov 15  2016 scgi_temp/
drwx------  2 nginx root  4096 Nov 15  2016 uwsgi_temp/

解决方法:

sudo chown -R nginx.nginx /var/cache/nginx/fastcgi_temp

  • 一次手动修改 nginx 用户组后使用 sudo systemctl status cs-nginx 启动报错:
Nov 23 02:55:38 v.cs.1 systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Nov 23 02:55:38 v.cs.1 nginx[3004]: /usr/sbin/nginx: error while loading shared libraries: cannot create cache for search path: Cannot allocate memory
Nov 23 02:55:38 v.cs.1 systemd[1]: cs-nginx.service: control process exited, code=exited status=127
Nov 23 02:55:38 v.cs.1 systemd[1]: Failed to start The NGINX HTTP and reverse proxy server.
Nov 23 02:55:38 v.cs.1 systemd[1]: Unit cs-nginx.service entered failed state.
Nov 23 02:55:38 v.cs.1 systemd[1]: cs-nginx.service failed.

但是通过 /usr/sbin/nginx 直接启动不报错

  • 对比 nginx 用户组:
# 正常
nginx:x:110:119:nginx user,,,:/nonexistent:/bin/false
# 异常
nginx:x:1001:1001:Nginx Server User:/home/nginx:/bin/false

于是重新设置成一下用户组,仍然无效

nginx:x:201:201:Nginx Server User:/nonexistent:/bin/false
  • 最后重新源码编译安装一次 nginx 系统自建一条 nginx 用户组
nginx:x:991:988::/home/nginx:/sbin/nologin

最后再按需要调整 nginx 用户组ID

sudo usermod -u 1001 nginx
sudo groupmod -g 1001 nginx
sudo find / -user 991 -exec chown -h nginx {} \;
sudo find / -group 988 -exec chgrp -h nginx {} \;

Comments

  • 牧马人 says: 2019-09-18 17:21:01

    江山代有才人出,各领风骚数百年.

Cor-Ethan, the beverage → www.iirii.com