当前位置:首页 > nginx > 正文

nginx开启与关闭(nginx使用指定配置启动)

  • nginx
  • 2024-03-22 07:41:01
  • 3917
开启 Nginx
确定 Nginx 安装目录,通常位于 /usr/local/nginx。
根据操作系统,使用以下命令之一:
bash
sudo nginx # Linux/macOS
nginx -c /usr/local/nginx/conf/nginx.conf # Windows
验证 Nginx 是否成功启动:
bash
sudo nginx -t
如果测试成功,则返回 "test is successful"。
关闭 Nginx
根据操作系统,使用以下命令之一:
bash
sudo nginx -s quit # Linux/macOS
nginx -s stop -c /usr/local/nginx/conf/nginx.conf # Windows
验证 Nginx 是否已关闭:
bash
sudo nginx -t
如果 Nginx 已停止,则返回 "nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)"。
示例要素
nginx 二进制文件的位置
-c 选项指定 Nginx 配置文件的位置
-s 选项指定要执行的操作(启动、停止、重新加载)
-t 选项用于测试 Nginx 配置
emerg 表示紧急错误