linuxnginx启动关闭命令
linuxnginx启动关闭命令详细介绍
在 Linux 系统中,你可以通过多种方式对 Nginx 进行启动和关闭操作,下面为你详细介绍:
1. 使用 systemctl 命令(适用于使用 systemd 的系统,如 CentOS 7 及以上、Ubuntu 16.04 及以上)
启动 Nginx
bash
systemctl start nginx
当你执行该命令时,Nginx 服务会开始运行。你可以通过sudo systemctl status nginx命令来查看 Nginx 的运行状态。
停止 Nginx
bash
systemctl stop nginx
执行此命令后,Nginx 服务会停止运行。
重启 Nginx
bash
systemctl restart nginx
若你对 Nginx 的配置文件进行了修改,可使用该命令重启 Nginx 使配置生效。
重新加载配置
bash
systemctl reload nginx
当你仅修改了 Nginx 的配置文件,且希望在不中断服务的情况下让新配置生效,就可以使用此命令。
设置开机自启
bash
systemctl nginx
使用该命令后,Nginx 会在系统启动时自动运行。
禁止开机自启
bash
systemctl disable nginx
执行此命令后,Nginx 将不会在系统启动时自动运行。
2. 使用 service 命令(适用于使用 SysVinit 的旧系统)
启动 Nginx
bash
nginx start
停止 Nginx
bash
nginx stop
重启 Nginx
bash
nginx restart
重新加载配置
bash
nginx reload
3. 直接使用 Nginx 可执行文件
启动 Nginx
bash
nginx
该命令会直接启动 Nginx 服务。
停止 Nginx
bash
nginx stop
此命令会快速停止 Nginx 服务。
优雅停止 Nginx
bash
nginx quit
912 nginx quit
该命令会在处理完当前的请求后再停止 Nginx 服务,避免正在处理的请求被中断。
重新加载配置
bash
nginx reload
912 nginx reload
同样,使用此命令可在不中断服务的情况下重新加载配置文件。