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/