开发者社区> 问答> 正文

nginx无法启动,PID file /var/run/nginx.pid not readable

使用的是阿里云ECS,操作系统选的centos 7.4,iptables和防火墙已配置80端口,
显示错误/var/run/nginx.pid文件不可读?请帮忙分析解决

[root@iZuf6igcce8m64xznu8cvvZ ~]# nginx -v
nginx version: nginx/1.14.0

[root@iZuf6igcce8m64xznu8cvvZ ~]# systemctl start nginx

[root@iZuf6igcce8m64xznu8cvvZ ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-06-21 08:28:54 CST; 6s ago

 Docs: http://nginx.org/en/docs/

Process: 26744 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE)
Process: 28132 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 28133 (nginx)
CGroup: /system.slice/nginx.service

       ├─28133 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
       └─28134 nginx: worker process

Jun 21 08:28:54 iZuf6igcce8m64xznu8cvvZ systemd[1]: Starting nginx - high performance web server...
Jun 21 08:28:54 iZuf6igcce8m64xznu8cvvZ systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
Jun 21 08:28:54 iZuf6igcce8m64xznu8cvvZ systemd[1]: Started nginx - high performance web server.

[root@iZuf6igcce8m64xznu8cvvZ ~]# ps -ef | grep nginx
root 28133 1 0 08:28 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
hyt_cms 28134 28133 0 08:28 ? 00:00:00 nginx: worker process
root 28142 28108 0 08:33 pts/0 00:00:00 grep --color=auto nginx
[root@iZuf6igcce8m64xznu8cvvZ ~]#

nginx配置文件如下:/etc/nginx/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 hyt_cms hyt_cms;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

pid /usr/local/nginx/nginx.pid;

Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

worker_connections 1024;

}

http {

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

# server {
#     listen       80 default_server;
#     listen       [::]:80 default_server;
#     server_name  _;
#     root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
#     include /etc/nginx/default.d/*.conf;

#     location / {
#     }

#     error_page 404 /404.html;
#         location = /40x.html {
#     }

#     error_page 500 502 503 504 /50x.html;
#         location = /50x.html {
#     }
# }

Settings for a TLS enabled server.

server {

listen 443 ssl http2 default_server;

listen [::]:443 ssl http2 default_server;

server_name _;

root /usr/share/nginx/html;

ssl_certificate "/etc/pki/nginx/server.crt";

ssl_certificate_key "/etc/pki/nginx/private/server.key";

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 10m;

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

location / {

}

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

}

我的配置文件:/etc/nginx/conf.d/hyt.conf

server {

listen       80 default_server;
listen       [::]:80 default_server;
server_name  hyt.cms.com;

location / {
    root   /home/project/hyt_cms/src/web/;
    proxy_pass       http://127.0.0.1:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-For $remote_addr;
}

location /static {
    root /home/project/hyt_cms/src/web/;
}

location /templates {
    root /home/project/hyt_cms/src/web/templates/;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

charset utf-8;
access_log  /var/log/nginx/hyt.cms.com.access.log;
error_log  /var/log/nginx/hyt.cms.com.error.log;

}

[root@iZuf6igcce8m64xznu8cvvZ nginx]# vim /etc/sysconfig/iptables

sample configuration for iptables service

you can edit this manually or use system-config-firewall

please do not ask us to add additional ports/services to this default configuration

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

展开
收起
湖桃 2018-06-21 10:40:49 20308 0
6 条回答
写回答
取消 提交回答
  • 解决方法: 1、killall nginx 2、systemctl start nginx

    2021-12-12 21:08:03
    赞同 1 展开评论 打赏
  • 这是因为 NGX 启动时 PID 文件并未产生,导致文件无法读取,因此产生如下报错:

    Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory
    

    访问nginx Service文件:

    vi /usr/lib/systemd/system/nginx.service
    

    在[Service]下面加入

    ExecStartPost=/bin/sleep 0.1
    

    作用是在执行可执行文件前等待 0.1s

    2020-07-26 19:03:46
    赞同 展开评论 打赏
  • 这个可能原因之一是: nginx主配置文件nginx.confpid指令配置的pid路径 与 nginx systemd service文件中的配置PIDFile路径不一致导致的。

    在nginx中默认配置为logs/nginx.pid, 而systemd service 默认为 /run/nginx.pid/var/var/nginx.pid

    2019-09-23 16:22:06
    赞同 3 展开评论 打赏
  • 楼主解决了吗?

    2019-07-24 16:24:27
    赞同 展开评论 打赏
  • 新人一枚

    1、停止nginx服务
    2、删除文件 rm /var/run/nginx.pid
    3、启动nginx服务

    2019-07-17 22:45:37
    赞同 展开评论 打赏
  • 旺旺:nectar2。

    题主您好,

    您是通过 yum 工具安装的nginx吗?

    是否可查看一下 /var/run/nginx.pid 文件是否存在,或 /var/run 目录的权限情况?

    2019-07-17 22:45:37
    赞同 展开评论 打赏
滑动查看更多
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载