nginx 服务页面 403
problem
nginx配置完成,打开页面,出现nginx的403报错
2022/02/22 11:50:32 [error] 32641#0: *80 "/root/blog/build/index.html" is forbidden (13: Permission denied), client: 124.160.215.188, server: _, request: "GET / HTTP/1.1", host: "121.199.5.94"
reason
- 启用用户出错
- 配置文件有问题
solution
【可能原因1 启用用户出错】
原因是:启动用户是nginx,需要改为root
如何查看启动用户?
- ps aux | grep “nginx: worker process” | awk ‘{print $1}’
- ps -ef | grep nginx
修改用户:vim /etc/nginx/nginx.conf
# user之前是nginx
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
【可能原因2 配置文件有问题】
server {
listen 9990;
server_name localhost;
location / {
root /path/to/dist; # ✅
alias /path/to/dist/; # ✅
alias /path/to/dist; # ❌
index index.html;
try_files $uri $uri/ /index.html;
}
}