在 Windows 上将 nginx 注册为系统服务

使用工具

GitHub - winsw/winsw: A wrapper executable that can run any executable as a Windows service, in a permissive license.

步骤

  1. 创建服务配置文件 nginx_service.xml
<service>
	<id>nginx</id>
	<name>Nginx Service</name>
	<description>Nginx Service</description>
	<logpath>D:\Software\nginx\logs</logpath>
	<logmode>roll</logmode>
	<executable>D:\Software\nginx\nginx.exe</executable>
	<startarguments></startarguments>
	<stoparguments>-s stop</stoparguments>
</service>
  1. 使用 winsw 注册
.\WinSW-x64.exe install "D:\Software\nginx\nginx_service.xml"
  1. 服务启动与停止
sc start nginx
sc stop nginx