Nginx registers system services under windows

 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)

[html]  view plain copy  
  1. <service>    
  2.  <id>nginx</id>    
  3.  <name>nginx</name>    
  4.  <description>nginx</description>    
  5.  <executable>D:\web_project\nginx-1.9.5\nginx.exe</executable>    
  6.  <logpath>D:\web_project\nginx-1.9.5\logs</logpath>    
  7.  <logmode>roll</logmode>    
  8.  <depend></depend>    
  9.  <startargument>-p D:\web_project\nginx-1.9.5</startargument>    
  10.  <stopargument>-p D:\web_project\nginx-1.9.5 -s stop</stopargument>    
  11. </service>    
Save it as myapp.xml file and put it in the directory you want.


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




The reason why the first one is recommended: If the second method is adopted, after starting the service, nginx will create two processes, and when the service is stopped, another process is not closed. This is what many people encounter after shutting down the service and still being able to access the website. At this point, you must use the taskkill /F /IM nginx.exe > nul command to clean up all processes to completely shut down. The first one does not have such a problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325858532&siteId=291194637