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. F - 等式(1/x + 1/y = 1/n)

    链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...

  2. 链式前向星写法下的DFS和BFS

    Input 5 7 1 2 2 3 3 4 1 3 4 1 1 5 4 5 output 1 5 3 4 2 #include<bits/stdc++.h> using namespace ...

  3. [haoi2009]巧克力

    鉴于河南是oi弱省,所以想来这道题也没什么人会翻出来写吧,而且这还是haoi2009的一道简单题目,所以估计也没几个人会写博客的,那么看在我这么弱的份上,我觉得是应该写一篇出来的. 这道题我是按照贪心 ...

  4. Linux命令之quota

    quota [-guqvswim] [-l | [-Q | -A] ] [-F quotaformat] quota [-qvswim] [-l | [-Q | -A]] [-F quotaforma ...

  5. [姿势]cpp - memset

    头文件:memory.h 可以刷的有: memset(array,,sizeof(array)); //全部赋0 memset(array,-,sizeof(array)); //全部赋-1 用法和用 ...

  6. Axis2 解析

    代码生成    Java to WSDL:WSDL to Java:XSD to WSDL:WSDL to XML:WSDL to SOAP:WSDL to Service: Apache Axis2 ...

  7. luogu P1107 最大整数

    题目描述 设有n个正整数 (n<=20), 将它们连接成一排, 组成一个最大的多位整数. 例如: n=3时, 3个整数13, 312, 343连接成的最大整数为: 34331213 又如: n= ...

  8. [Codeforces 15E] Triangle

    Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...

  9. [CF403D]Beautiful Pairs of Numbers

    题意:给定$n,k$,对于整数对序列$\left(a_1,b_1\right),\cdots,\left(a_k,b_k\right)$,如果$1\leq a_1\leq b_1\lt a_2\leq ...

  10. Problem B: 零起点学算法17——2个数比较大小

    #include<stdio.h> int main() { int n,m; while(scanf("%d %d",&n,&m)!=EOF) if( ...