使用Nginx部署前后分离项目时,访问时Nginx出现403 forbidden,发现Nginx日志文件报如下错误:
2021/09/10 11:31:25 [error] 42415#0: *1 "/home/web/web-d/index.html" is forbidden (13: Permission denied), client: 192.168.1.1, server: 192.168.1.101, request: "GET / HTTP/1.1", host: "192.168.1.101:5500" 2021/09/10 11:31:25 [error] 42415#0: *1 open() "/home/web/web-d/favicon.ico" failed (13: Permission denied), client: 192.168.1.1, server: 192.168.1.101, request: "GET /favicon.ico HTTP/1.1", host: "192.168.1.101:5500", referrer: "http://192.168.1.101:5500/"
将nginx.conf文件中的 user 对应的nginx用户改为 root ,改完后重启Nginx,页面即可正常访问!
说明:Nginx启动方式如下
cd /usr/local/nginx/sbin 进入Nginx下的sbin目录 ./nginx -c /usr/local/nginx/conf/nginx.conf 执行启动命令 pkill nginx 干掉Nginx ps -ef | grep nginx 查看Nginx