资讯专栏INFORMATION COLUMN

Failed to Stop or Restart Nginx Server Through Ser

不知名网友 / 2061人阅读

Many people are accustomed to start a Nginx web server through init scripts and then they can control the state of the server through service command, such as sudo service nginx restart. But sometimes unobvious config error makes the scripts failed to work. Here I will show an error related to pid directive in the config file of nginx, which defaultly located at /opt/nginx/conf/nginx.conf.

As ignored by many people, some init scripts assump there is a pid file of nginx located at /var/run/nginx.pid, but in the fact, the default pid file for nginx is /opt/nginx/logs/nginx.pid. Because the scripts can"t get the correct pid or even get nothing, they failed to stop the nginx process, some tasks dependent on it will be failed too, for example, you are not able to restart the server.

To resolve this problem, you need to:

Force terminating your server through:

$ sudo service nginx destroy

Open your nginx config file to edit:

$ sudo vim /opt/nginx/conf/nginx.conf

Specify the path of your pid file:

# /opt/nginx/conf/nginx.conf
pid /var/run/nginx.pid

After saving your change, start your server now:

$ sudo service nginx start

To confirm that your pid config has taken effect, you can cat your pid file and/or try to restart your server through service command:

$ cat /var/run/nginx.pid
$ sudo service nginx restart

As expected, you will see the screen out "OK" for your operations.

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39084.html

相关文章

  • "/alidata/server/nginx/logs/nginx.pid" f

    摘要:基于阿里云,版本是先废话下进程分为进程和进程,开始运行后我们可以通过查看他的的在之后会把它的进程写到文件中。之后就会把此掉,随之这个文件也会被删除。此时你文件得到的一串数字和上述中的数据是一致的。 基于阿里云,版本是 CentOS release 5.8 (Final) 先废话下,Nginx进程分为master进程和worker进程,nginx开始运行后我们可以通过 ps aux|ge...

    QiuyueZhong 评论0 收藏0
  • nginx 负载均衡搭建

    摘要:客户请求头缓冲大小默认会用这个来读取值,如果设定通过上传文件的大小磁盘和之间互相拷贝数据或任意两个文件描述符。 环境说明 192.168.1.208 Nginx负载服务器 192.168.1.210 webA服务器 PHP memcache xcache mysql 192.168.1.211 webB服务器 PHP memcache xcache webA/webB...

    endiat 评论0 收藏0
  • nginx 负载均衡搭建

    摘要:客户请求头缓冲大小默认会用这个来读取值,如果设定通过上传文件的大小磁盘和之间互相拷贝数据或任意两个文件描述符。 环境说明 192.168.1.208 Nginx负载服务器 192.168.1.210 webA服务器 PHP memcache xcache mysql 192.168.1.211 webB服务器 PHP memcache xcache webA/webB...

    leo108 评论0 收藏0

发表评论

0条评论

不知名网友

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<