windows下常用的nginx命令

  • start nginx : 启动nginx
  • nginx.exe -c conf/nginx.conf 按照指定配置去启动nginx
  • nginx -t -c conf/nginx.conf  :检测nginx是否配置正确
  • nginx -s reload  :修改配置后重新加载生效
  • nginx -s stop  :快速停止nginx,可能并不保存相关信息.
  • nginx -s quit  :完整有序的停止nginx,并保存相关信息.
 
注意:以下几种方式可能会提示报错:
1.git bash :

--@S4--898- MINGW64 /d/softwares/nginx-1.24.0
$ nginx -s reload
bash: nginx: command not found

2.Windows PowerShell :

PS D:\softwares\nginx-1.24.0> nginx -s reload
nginx : 无法将“nginx”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 行:1 字符: 1
+ nginx -s reload
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (nginx:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: 找不到命令 nginx,但它确实存在于当前位置。默认情况下,Windows PowerShell 不会从当前位置加载命令 。如果信任此命令,请改为键入“.\nginx”。有关详细信息,请参阅 "get-help about_Command_Precedence"。

 

 
解决方法:
1.可以切换到cmd中执行命令,如下所示:
D:\softwares\nginx-1.24.0>nginx -s reload
D:\softwares\nginx-1.24.0>nginx -s stop
D:\softwares\nginx-1.24.0>start nginx

 

2.在Windows PowerShell将命令中的nginx 改为./nginx 或者.\nginx , 在git bash改为./nginx ,便可正常操作  。如下所示: 
 
PowerShell:

PS D:\softwares\nginx-1.24.0> ./nginx -t -c conf/nginx.conf
nginx: the configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf syntax is ok
nginx: configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf test is successful
PS D:\softwares\nginx-1.24.0> start nginx
PS D:\softwares\nginx-1.24.0> ./nginx -s reload
PS D:\softwares\nginx-1.24.0> ./nginx -s reopen
PS D:\softwares\nginx-1.24.0> ./nginx -t -c conf/nginx.conf
nginx: the configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf syntax is ok
nginx: configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf test is successful

PS D:\softwares\nginx-1.24.0> .\nginx -t -c conf/nginx.conf
nginx: the configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf syntax is ok
nginx: configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf test is successful

 

git bash:

--@S4--898- MINGW64 /d/softwares/nginx-1.24.0
$ ./nginx -t -c conf/nginx.conf
nginx: the configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf syntax is ok
nginx: configuration file D:\softwares\nginx-1.24.0/conf/nginx.conf test is successful

 

3. 将要执行的命令保存到 .bat文件内,双击执行,如下:

startup.bat:
@echo off 
rem 如果启动前已经启动nginx并记录下pid文件,会kill指定进程 
nginx.exe -s stop 
rem 测试配置文件语法正确性 nginx.exe
-t -c conf/nginx.conf
rem 显示版本信息 nginx.exe -v
rem 按照指定配置去启动nginx nginx.exe
-c conf/nginx.conf

stop.bat:

nginx.exe -s quit

 

 
posted on 2023-08-08 13:20  风景1573  阅读(1210)  评论(0编辑  收藏  举报