Nginx
Nginx 500 Internal Server Error
Permission denied
1、将项目通过 github actions 上传到阿里云 ecs 上;
2、配置域名解析
3、配置 nginx
4、访问网址显示 Nginx 500 Internal Server Error
查看 Nginx error log 提示 Permission denied
bash
[root@zhoujw conf.d]# sudo tail -f /var/log/nginx/error.log
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [crit] 11949#11949: *94 stat() "/root/zhoujw/app/stocksand/dist/index.html.html" failed (13: Permission denied), client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
2024/02/23 22:11:48 [error] 11949#11949: *94 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 159.203.119.184, server: gp.zhoujw.com, request: "GET /2c4Z930YWZvcuVD8sCU3uY3Y6ei.jsp HTTP/1.1", host: "47.101.141.27"
5、定位原因:nginx 工作用户和服务器启动用户不一致导致的
bash
[root@zhoujw conf.d]# ps aux | grep nginx
nginx 11949 0.0 0.1 47268 2268 ? S 22:07 0:00 nginx: worker process
root 13021 0.0 0.1 47264 2260 ? Ss 18:48 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
root 18803 0.0 0.0 112708 984 pts/0 R+ 22:18 0:00 grep --color=auto nginx
解决方案:
修改 nginx 工作用户和服务器启动用户一致
bash
[root@zhoujw conf.d]# vim /etc/nginx/nginx.conf
将 user nginx;
改为 user root;
重启 nginx
bash
[root@zhoujw conf.d]# nginx -s reload