如何在Linux上重启nginx

如何重新启动nginx

使用“systemctl”,还有两个不同的选项用于重新启动nginx:

  • reload - 重新加载配置文件,但不会完全退出nginx或者关闭当前连接
  • restart - 完全重新启动nginx,其还关闭连接并重新加载配置文件

这些命令还将检查配置文件是否有错误。
但是在重新加载或者重新启动NGINX之前,最好事先检查配置文件是否存在潜在的语法错误。否则可能导致NGINX进程停止时间过长。

$sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

确认配置文件没问题后, 使用以下命令之一进行配置更改以生效。

  • 优雅地重新加载nginx Web服务器:
$sudo systemctl reload nginx
  • 完全重新启动nginx Web服务器:
$sudo systemctl restart nginx

我们还可以使用systemctl检查nginx的当前状态:

$sudo systemctl status nginx
日期:2020-07-07 20:56:32 来源:oir作者:oir