yum安装nginx,安装一切正常,但是访问时报403forbidden,下面这篇文章主要给大家介绍了关于Nginx 403 forbidden错误的原因以及解决方法,需要的朋友可以参考下
一、由于启动用户和nginx工作用户不一致所致
1.1查看nginx的启动用户,发现是nginx,而为是用root启动的
[root@iZwz96xkbmh1v1n08cvb5dZ /]# ps aux|grep nginx
root 2773 0.0 0.0 9068 844 ? Ss 13:56 0:00 nginx: master process /usr/sbin/nginx
nginx 2774 0.0 0.1 9476 2360 ? S 13:56 0:00 nginx: worker process
root 2916 0.0 0.0 221460 836 pts/0 R+ 13:59 0:00 grep --color=auto nginx
1.2将nginx.config的user改为和启动用户一致,
命令:vim etc/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user root; //就是这里
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
1.3 也可以使用如下命令直接查看
ps aux|grep nginx
[root@iZwz96xkbmh1v1n08cvb5dZ nginx]# ps aux|grep nginx
root 2983 0.0 0.0 9068 848 ? Ss 14:02 0:00 nginx: master process /usr/sbin/nginx
root 2984 0.0 0.1 9476 2356 ? S 14:02 0:00 nginx: worker process
root 2986 0.0 0.0 221460 848 pts/0 R+ 14:02 0:00 grep --color=auto nginx
二、缺少index.html,就是配置文件中index index.html index.htm这行中的指定的文件。
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /root/xiaoaodi/index/dist;
index index.html;
}
如果在/data/www/下面没有index.html的时候,直接文件,会报403 forbidden。
三、权限问题,如果nginx没有web目录的操作权限,也会出现403错误。
解决办法:修改web目录的读写权限,或者是把nginx的启动用户改成目录的所属用户,重启Nginx即可解决
chmod -R 777 /data
chmod -R 777 /data/www/
[root@iZwz96xkbmh1v1n08cvb5dZ data]# chmod 777 www
[root@iZwz96xkbmh1v1n08cvb5dZ data]# ls -l
total 4
drwxrwxrwx 3 root root 4096 Apr 10 14:26 www
总结
到此这篇关于Nginx 403 forbidden错误的原因以及解决方法的文章就介绍到这了,更多相关Nginx 403 forbidden错误解决内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
织梦狗教程
本文标题为:Nginx 403 forbidden错误的原因以及解决方法


基础教程推荐
猜你喜欢
- 为Win2003服务器打造铜墙铁壁的方法步骤 2022-09-01
- Centos 安装Django2.1 2023-09-24
- P3 利用Vulnhub复现漏洞 - Apache SSI 远程命令执行漏洞 2023-09-10
- Centos7 nginx的安装以及开机自启动的设置 2023-09-22
- Docker容器操作方法详解 2022-11-13
- RFO SIG之openEuler AWS AMI 制作详解 2022-12-28
- Apache Kafka 2.5 稳定版发布,新特性抢先看 2023-09-11
- windows环境下apache-apollo服务器搭建 2023-09-10
- 通过StatefulSet部署有状态服务应用实现方式 2022-10-01
- Apache CarbonData 1.0.0发布及其新特性介绍 2023-09-11