使用的是阿里云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
user hyt_cms hyt_cms;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
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 {
# }
# }
}
我的配置文件:/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
*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
这是因为 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
这个可能原因之一是: nginx主配置文件nginx.conf
中 pid
指令配置的pid路径 与 nginx systemd service文件中的配置PIDFile
路径不一致导致的。
在nginx中默认配置为logs/nginx.pid
, 而systemd service 默认为 /run/nginx.pid
或 /var/var/nginx.pid
题主您好,
您是通过 yum
工具安装的nginx吗?
是否可查看一下 /var/run/nginx.pid
文件是否存在,或 /var/run
目录的权限情况?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。