Nginx 启动脚本/重启脚本

第一步

先运行命令关闭nginx

[plain] view plain copy

  1. sudo kill `cat /usr/local/nginx/logs/nginx.pid`

第二步

[html] view plain copy

  1. vi /etc/init.d/nginx

输入以下内容

[plain] view plain copy

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemin
  4. #
  5. # chkconfig:   - 85 15
  6. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. #               proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config:      /usr/local/nginx/conf/nginx.conf
  10. # pidfile:     /usr/local/nginx/logs/nginx.pid
  11. # Source function library.
  12. . /etc/rc.d/init.d/functions
  13. # Source networking configuration.
  14. . /etc/sysconfig/network
  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0
  17. nginx="/usr/local/nginx/sbin/nginx"
  18. prog=$(basename $nginx)
  19. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  20. lockfile=/var/lock/subsys/nginx
  21. start() {
  22. [ -x $nginx ] || exit 5
  23. [ -f $NGINX_CONF_FILE ] || exit 6
  24. echo -n $"Starting $prog: "
  25. daemon $nginx -c $NGINX_CONF_FILE
  26. retval=$?
  27. echo
  28. [ $retval -eq 0 ] && touch $lockfile
  29. return $retval
  30. }
  31. stop() {
  32. echo -n $"Stopping $prog: "
  33. killproc $prog -QUIT
  34. retval=$?
  35. echo
  36. [ $retval -eq 0 ] && rm -f $lockfile
  37. return $retval
  38. }
  39. restart() {
  40. configtest || return $?
  41. stop
  42. start
  43. }
  44. reload() {
  45. configtest || return $?
  46. echo -n $"Reloading $prog: "
  47. killproc $nginx -HUP
  48. RETVAL=$?
  49. echo
  50. }
  51. force_reload() {
  52. restart
  53. }
  54. configtest() {
  55. $nginx -t -c $NGINX_CONF_FILE
  56. }
  57. rh_status() {
  58. status $prog
  59. }
  60. rh_status_q() {
  61. rh_status >/dev/null 2>&1
  62. }
  63. case "$1" in
  64. start)
  65. rh_status_q && exit 0
  66. $1
  67. ;;
  68. stop)
  69. rh_status_q || exit 0
  70. $1
  71. ;;
  72. restart|configtest)
  73. $1
  74. ;;
  75. reload)
  76. rh_status_q || exit 7
  77. $1
  78. ;;
  79. force-reload)
  80. force_reload
  81. ;;
  82. status)
  83. rh_status
  84. ;;
  85. condrestart|try-restart)
  86. rh_status_q || exit 0
  87. ;;
  88. *)
  89. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  90. exit 2
  91. esac

保存退出

第三步

[html] view plain copy

  1. chmod +x /etc/init.d/nginx

第四步

[plain] view plain copy

  1. /sbin/chkconfig nginx on

检查一下

[plain] view plain copy

  1. sudo /sbin/chkconfig --list nginx
  2. nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

完成!

之后,就可以使用以下命令了

[plain] view plain copy

    1. service nginx start
    2. service nginx stop
    3. service nginx restart
    4. service nginx reload
    5. /etc/init.d/nginx start
    6. /etc/init.d/nginx stop
    7. /etc/init.d/nginx restart
    8. /etc/init.d/nginx reload
时间: 2024-08-18 07:39:40

Nginx 启动脚本/重启脚本的相关文章

linux下nginx启动停止重启控制脚本

这是控制nginx服务的脚本文件,包括控制nginx的启动.重启.停止.平滑重启.对配置文件的额检查. [[email protected] ~]# cat nginx.sh #!/bin/env bash # description:nginx server   ###必须加描述 # nginx - this script is used to control nginx service # processname nginx # chkconfig: - 85 15 # edit by su

nginx 启动,关闭,重启

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream;

nginx启动,重启,关闭命令

nginx启动,重启,关闭命令 停止操作停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的步骤1:查询nginx主进程号ps -ef | grep nginx在进程列表里 面找master进程,它的编号就是主进程号了.步骤2:发送信号从容停止Nginx:kill -QUIT 主进程号快速停止Nginx:kill -TERM 主进程号强制停止Nginx:pkill -9 nginx 另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx

URL检查 跳板机 创建用户 Nginx启动 随机密码的脚本

URL检查 #!/bin/bashpath=/home/scriptsMAIL_GROUP="[email protected] [email protected]"PHOTO_GROUP="13502693568 18023569846". /etc/init.d/functionscheck_count=0 url_list(http://www.baidu.comhttp://blog.51cto.comhttp://www.qq.com http://192

nginx启动,重启,关闭

1.nginx启动: a.     /usr/path/sbin/nginx -c [/etc/path/nginx.conf] 中括号中为指定加载的配置文件,不指定则加载默认配置文件 b.     cd进入sbin目录    ./nginx c. centos 7中可用 systemctl start nginx 若出现问题不能启动,有可能是nginx重复启动,killall -9 nginx,再启动即可. 2.nginx关闭: a. kill -9 nginx  强制kill b. ps -

nginx启动、重启、关闭

一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/nginx/sbin ./nginx -s reload 判断配置文件是否正确 nginx -t -c /usr/local/nginx/conf/nginx.conf 或者 cd /usr/local/nginx/sbin ./nginx -t 三.关闭 查询nginx主进程号 ps -ef | grep

nginx 启动,重启等相关命令

nginx -t 测试 配置文件是否正确,同时可以查看配置文件路径 nginx -c /usr/local/nginx/conf/nginx.conf   启动nginx ps -ef|grep nginx 查看nginx 进程号 左边前三个数字 分别 为UID(被该UID所拥有).PID (程序ID,即进程号).PPID (上级父程序ID) 杀死进程 kill -QUIT 2072 重启 nginx: nginx -s reload

nginx 启动/停止/重启 BAT

cls @ECHO OFF SET NGINX_PATH=D: SET NGINX_DIR=D:\Hack\nginx\color 0a TITLE Nginx 管理程序 Power By AntsGOTO MENU :MENU CLS ECHO. ECHO. * * * *  Nginx 管理程序 Power By Ants * * * * * ECHO. * * ECHO. * 1 启动Nginx * ECHO. * * ECHO. * 2 关闭Nginx * ECHO. * * ECHO.

linux配置Nginx启动,停止

Nginx 启动.重启.停止脚本 第一步 先运行命令关闭nginx sudo kill `cat /usr/local/nginx/logs/nginx.pid` 第二步 vi /etc/init.d/nginx 输入以下内容 : #!/bin/bash # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server