Nginx 管理命令

  1. 查看版本
  • nginx -v
  1. 检查配置
  • nginx -t
    检查配置并显示
  • nginx -T
  1. 检查配置期间禁止非错误消息
  • nginx -q
  1. 查看进程
  • ps -aux | grep nginx
  1. nginx主进程发送信号
  • nginx -s stop # 直接停止nginx
  • nginx -s quit # 优雅退出nginx
  • nginx -s reopen # 重新打开日志文件
  • nginx -s reload # 重载配置
  1. 启动nginx
  • service nginx start
  • systemctl nginx start
  1. 开机自启动
  • systemctl enable nginx
  1. 停止nginx
  • service nginx stop
  • `systemctl nginx stop-
  1. 重启nginx
  • service nginx restart
  • systemctl nginx restart
  1. 重载nginx
  • service nginx reload
  • systemctl nginx reload

利用crontab定时重启nginx

/etc/init.d/cron status         #查看状态
/etc/init.d/cron start          #启动crontab服务
service cron start              #启动cron服务
/etc/init.d/cron stop           #停止crontab服务
/etc/init.d/cron reload         #重载定时任务
service cron restart            #重启cron服务
crontab -e                      # 编辑当前用户的crontab
crontab -l                      # 查看定时任务列表
  • crontab 每3分钟重启一次 */3 * * * * systemctl nginx restart
  • crontab 每3小时重启一次 00 */3 * * * systemctl nginx restart
  • crontab 每天0点重启一次 0 0 * * * systemctl nginx restart
  • crontab 每周重启一次 0 0 * * 0 systemctl nginx restart
  • crontab 每月重启一次 0 0 1 * * systemctl nginx restart
  • crontab 每年重启 一次 0 0 1 1 * systemctl nginx restart