1. Download two Microsoft tools: instsrv.exe1_srvany.exe
Go to the Microsoft website to download and install Windows Server 2003 Resource Kit tools(rktools.exe), which includes all the necessary tools mentioned in the title.
? Http://download.microsoft.com/download/8/e/c/8ec3a7d8-05b4-440a-a71e-ca3ee25fe057/rktools.exe
2. Run the command
In the rktools installation directory (generally in the c: \ Program Files \ Windows resource kits \ toolsdirectory, you can find these two programs. Before running the command, make sure to copy srvany.exe to the nginx installation (decompress) directory and run:
Command code
Instsrv nginx D: \ nginx \ srvany.exe
In this way, a service named nginx is installed. Also, register srvany.exe as a service nginx. Net start nginx, srvany.exe will be run.
3. Configure the Nginx running parameters to run the "D: \ nginx \ nginx.exe" program.
You can directly import the configuration to the Registry.
Window Register Code
Windows Registry Editor Version 5.00
? [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ nginx \ Parameters]
"Application" = "D: \ nginx \ nginx.exe"
"AppParameters" = ""
"AppDirectory" = "d: \ nginx \\"
Now you can find the service in Control Panel> administrator tools> service, and start and stop it.
However, when the Nginix service is stopped, you can still see the website in the browser. Check the process and you will find that Nginx has started two nginx processes (according to nginx. conf configuration worker_processes 1;), the Fork process is obviously not stopped, and the result is that nginx will never be shut down. Therefore, use the taskkill command to completely disable nginx:
Command code
Taskkill/F/IM nginx.exe> nul
The result is to write a stop_nginx script to process all the operations stopped by nginx.
Command code
@ Echo off
Echo Stopping nginx service...
Net stop nginx
Echo Kill nginx process...
Taskkill/F/IM nginx.exe> nul
By the way, to delete a service, run the following command:
Command code
SC delete Nginx
Speaking of this, you will surely rethink: if you write a start_nginx script, is it necessary to use the windows service? Running nginx in Script Mode does not seem to have any difference except the console window. A good writer writes runhiddenconsole.exe to hide the console window. It seems that you do not have to consider using the windows service method at all.
Let's go back to the Peak. Don't forget our original intention. You can still run the nginx process when you log out of the windows service. If you want to run the script in this way, you have to pay a lot of attention, the conclusion is that the windows Service is still necessary, but it is only used to start nginx. Use the preceding script to stop nginx.