1. Need to use the "Windows Service Wrapper" gadget, project address: https://github.com/kohsuke/winsw (for learning)
2. Download address: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe
3. After downloading the tool, place it in the Nginx installation directory and rename it to nginx-service.exe to create a configuration file nginx-service.xml (the name must be the same as the tool name) There is Chinese, otherwise it will cause the publication to fail)
4. Create nginx-service.exe.config (to support NET 4.0 runtime, only NET 2.0 runtime is supported by default)
5. The content of nginx-service.xml is as follows: (remember to modify the path)
<service> <id>nginx</id> <name>Nginx Service</name> <description>High Performance Nginx Service</description> <logpath>D:\Web\nginx\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>10240</sizeThreshold> <keepFiles></8keepFiles> </log> <executable>D:\Web\nginx\nginx.exe</executable> <startarguments>-pD:\Web\nginx</startarguments> <stopexecutable>D:\Web\nginx\nginx.exe</stopexecutable> <stoparguments>-pD:\Web\nginx -s stop</stoparguments> </service>
6. The content of nginx-service.exe.config is as follows:
<configuration> <startup> <supportedRuntime version="v2.0.50727" /> <supportedRuntime version="v4.0" /> </startup> <runtime> <generatePublisherEvidence enabled="false"/> </runtime> </configuration>
7. Important: Run cmd as an administrator, jump to the directory where nginx is located, install nginx service, execute the command:
nginx-service.exe install
Uninstall:
nginx-service.exe uninstall or sc delete service name
At this time, the windows service of nginx has been installed, run-> services.msc to open the service list
8. Start the service, close the service command
Start: net start nginx
Close: net stop nginx
Note: After installing as a service, nginx -s reload is not available and an error will be reported
9. Restart the computer, and then open the service list to view, this time the service has been self-started
Reference: https://www.dazhuanlan.com/2019/12/16/5df6fbb4975a8/