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:

  1. Force terminating your server through:
 
$ sudo service nginx destroy
  1. Open your nginx config file to edit:
 
$ sudo vim /opt/nginx/conf/nginx.conf
  1. Specify the path of your pid file:
 
# /opt/nginx/conf/nginx.conf
pid /var/run/nginx.pid
  1. After saving your change, start your server now:
 
$ sudo service nginx start
  1. 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.

Failed to Stop or Restart Nginx Server Through Serevice Command(nginx进程不能停止重启)的更多相关文章

  1. Setting up Django and your web server with uWSGI and nginx

    https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html Setting up Django and your we ...

  2. [r]Setting up Django and your web server with uWSGI and nginx

    Setting up Django and your web server with uWSGI and nginx This tutorial is aimed at the Django user ...

  3. 配置 nginx server 出现nginx: [emerg] "root" directive is duplicate in /etc/nginx/server/blogs.conf:7

    在配置nginx 虚拟机时,执行 sudo /usr/sbin/nginx -t 报下面的错误: nginx: [emerg] nginx: configuration file /etc/nginx ...

  4. 把Nginx加为系统服务(service nginx start/stop/restart)

    1.编写脚本,名为nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - ...

  5. How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu

    sudo apt-get update sudo apt-get install nginxsudo mkdir -p /var/www/example.com/html sudo chown -R ...

  6. TinyCore Nginx server with php-cgi and vsftpd

    http://blog.matchgenius.com/tinycore-nginx-server-with-php-cgi-and-vsftpd/ Create fast testing serve ...

  7. nginx Server names

    通配符名称 正則表達式名称 混合名称 优化 兼容性 server名称定义使用的server_name指令和决定哪个server块用于一个给定的请求. 參见"怎样Nginx处理一个请求&quo ...

  8. nginx的开机自启、server命令启动、nginx.conf配置

    1.将Nginx设置为开机自动启动 a.当上面6步完成之后,说明安装已经完全成功了,但是每次开机我们面临的一个问题,就是每次都要执行命令(1: cd /usr/local/nginx/sbin/   ...

  9. 用Keepalived搭建双Nginx server集群,防止单点故障

    综述: 浏览器访问虚拟IP: 192.168.1.57, 该虚拟IP被Keepalived接管,两个Keepalived进程分别运行在物理IP为192.168.1.56和192.168.1.59服务器 ...

随机推荐

  1. VX的快捷方式(转)

    转载自:http://blog.csdn.net/xueying_/article/details/7679042 “文本操作”快捷键 命令名 快捷键 说明 编辑.折叠到定义 Ctrl + M,Ctr ...

  2. ansible管理window

    设置window以支持远程执行命令======================================= 升级powershell到3.0+-------------------------- ...

  3. Tomcat线程池实现

    目前市场上常用的开源Java Web容器有Tomcat.Resin和Jetty.其中Resin从V3.0后需要购买才能用于商业目的,而其他两种则是纯开源的.可以分别从他们的网站上下载最新的二进制包和源 ...

  4. 【最近公共祖先】【块状树】CODEVS 1036 商务旅行

    在线块状树LCA模板. #include<cstdio> #include<vector> #include<algorithm> #include<cmat ...

  5. 【强联通分量缩点】【最长路】【spfa】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的讲学计划

    10分算法:对于城市网络为一条单向链的数据, 20分算法:对于n<=20的数据,暴力搜出所有的可能路径. 结合以上可以得到30分. 60分算法:分析题意可得使者会带着去的城市也就是这个城市所在强 ...

  6. STL之priority_queue2

    描述 使用STL中的优先队列,将一个字符串中的各个字符按照ASCII从小到大顺序排列. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { int n; cin&g ...

  7. matlab和c混合编程

    参考: http://blog.sciencenet.cn/blog-620659-579885.html http://baike.baidu.com/link?url=HnHd3lU9mcVXwh ...

  8. 点击VS2010调试按钮无反应

    使用vs打开网站的方式分为两种. 1) 点击“在浏览器中查看”无反应的话,就点击“浏览方式”,选择一个浏览器进行查看. 2)第二中是直接点击调试按钮,结果浏览器无反应. 以上两种方法不成功的原因都是浏 ...

  9. 从cmd连接mysql数据库控制台

    在cmd中进入mysql安装目录的bin目录然后执行命令 mysql -uuser -ppassword database比如用户名为root,密码为mysql,数据库为test命令如下mysql - ...

  10. 【mybatis】mybatis 查询mysql 长编码的查询使用 正向查询和反向查询,避免数据库关系 递归查询的 解决方案

    长编码存储规则为: 父级长编码+":"+自己的uid 例如最顶级GoodsType-->uid = 123  --->longCode= 123: 子级GoodsTyp ...