nginx 遇到的一堆坑

1 Centos7.5中Nginx报错:nginx: [error] invalid PID number “” in “/run/nginx.pid” 解决方法

服务器重启之后,执行 nginx -t 是OK的,然而在执行 nginx -s reload 的时候报错
nginx: [error] invalid PID number “” in “/run/nginx.pid”
出现原因:nginx未开启所以无法重启
解决方法:
需要先执行

 nginx -c /etc/nginx/nginx.conf
 nginx -s reload

如果发现
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
说明80端口被占用,杀掉这个进程:
[root@localhost ~]# killall -9 nginx
nginx -c /etc/nginx/nginx.conf
nginx -s reload

2 重启的时候Job for nginx.service failed because the control process exited with error code

首先需要杀掉nginx进程
killall -9 nginx
然后启动nginx
systemctl start nginx.service

3 Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

3.1 SELinux设置为开启状态(enabled)的原因。

权限拒绝,经检查发现是开启selinux 导致的。 直接关闭

getenforce 这个命令可以查看当前是否开启了selinux 如果输出 disabled 或 permissive 那就是关闭了
如果输出 enforcing 那就是开启了 selinux

1、临时关闭selinux
setenforce 0 ##设置SELinux 成为permissive模式
setenforce 1 ##设置SELinux 成为enforcing模式

2、永久关闭selinux
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启系统即可

3.2 缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件。
    server {  

    listen       80;  

     server_name  localhost;  

   index  index.php index.html;  

      root  /data/www/;

   }

如果在/data/www/下面没有index.php,index.html的时候,直接文件,会报403 forbidden。

3.3 由于启动用户和nginx工作用户不一致所致

查看nginx的启动用户,发现是nobody,而为是用root启动的

命令:ps aux | grep "nginx: worker process" | awk'{print $1}'

将nginx.config的user改为和启动用户一致,

vi conf/nginx.conf

user nginx 改为user root

3.4 权限问题,如果nginx没有web目录的操作权限,也会出现403错误。

解决办法:修改web目录的读写权限,或者是把nginx的启动用户改成目录的所属用户,重启Nginx即可解决

chmod -R 777 /data

 chmod -R 777 /data/www/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值