【nginx配置】linux环境常用命令与常见问题

文章介绍了Nginx出现403Forbidden错误的两个主要原因及其解决策略。一是启动用户与Nginx工作用户不一致,需要修改nginx.conf配置文件中的user设置。二是缺少index.html文件或配置不当。三是权限问题,确保Nginx对web目录有足够权限,可以通过修改目录权限或调整启动用户来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常见问题

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:
Official Russian Documentation:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值