If nginx is running on the windows server, you will definitely face a problem, that is, what to do if you restart it, the website cannot be accessed, and it is very troublesome to start it manually every time. However, as a software of linux, it is quite troublesome to register nginx as a service under windows. Referring to the information on the Internet, there are currently only two ways.
The first is to use the Windows Service Wrapper (highly recommended, for reasons at the bottom of this article)
1. Tool download address: http://pan.baidu.com/s/1kVPEcCJ (file cancellation)
Newly provided download path: https://github.com/kohsuke/winsw/releases
2. After decompression, rename the latest 1.9 version to "myapp.exe" and put it in the nginx directory
3. Create a new text document with the following content: (The path inside is modified according to your own situation)
- <service>
- <id>nginx</id>
- <name>nginx</name>
- <description>nginx</description>
- <executable>D:\web_project\nginx-1.9.5\nginx.exe</executable>
- <logpath>D:\web_project\nginx-1.9.5\logs</logpath>
- <logmode>roll</logmode>
- <depend></depend>
- <startargument>-p D:\web_project\nginx-1.9.5</startargument>
- <stopargument>-p D:\web_project\nginx-1.9.5 -s stop</stopargument>
- </service>
4. Run cmd to execute the following command: (The path is modified according to your own situation)
D:\web_project\nginx-1.9.5\myapp.exe install
5. Enter the system service to see nginx. (Finish)
The second is the instsrv / servany way.
1. Tool download location: http://eastedu.bl-changjiang.com/UploadFiles/2006-5/511179043.rar
2. After decompression, copy srvany.exe to the nginx directory
3. Run cmd to switch the path to the nginx directory and execute the following command:
instsrv Nginx c:\nginx\srvany.exe
4. Edit a nginx.reg file in the nginx directory
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NGINX\Parameters]
"Application"="C:\\nginx\\nginx.exe"
"AppParameters"=""
"AppDirectory"="C:\\nginx\\"
5. Associate the service with the program and execute it from the command line
regedit /s nginx.reg
6. Edit the start-nginx script start-nginx.bat (close the script without changing), let the program run as a service
@ECHO
OFF net stop nginx
net start nginx
EXIT