随笔 - 33  文章 - 0  评论 - 5  阅读 - 15万

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   风景1573  阅读(3426)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示