Install Nginx as a service under Windows

Source: Internet
Author: User

See Nginx Today this small server Software official version updated to 1.4.2, want to play it. This server software is small, but powerful, open source software, has a good performance, by many individuals, enterprises, even large enterprises use!

Because it is under Windows, you can only double-click the run and then manage it with the following command:

Nginx/win32 is run in a console program, not a Windows service mode. Server mode is currently a development attempt, NGINX/WIN32 can use the following switches to manage it:
nginx-s Stop             Quickly shut down Nginx, may not save the relevant information, and quickly terminate the Web service. (Quick exit)Nginx-s quit             smooth Nginx, save the relevant information, there is scheduled to end the Web service. (Smooth exit)nginx-s Reload        changes the Nginx-related configuration and needs to reload the configuration. nginx-s reopen re-open the log file (reload configuration)       . (Reload Log)

If you can install it as a Windows service to run, it's cool!! Found a Windows Service installation tool on the Internet: SRVINSTW. This tool is capable of installing nginx as a service, but cannot be started normally and cannot be run. Just forget it!

After a search, finally found a solution:

Here we need to use a software:Windows Service Wrapper, this software is also open source, and has not been updated for a long time, I found the last version is 1.9, if you see a new version, remember to notify me Oh! Use this software to install the program as a service run.

Here's how to do it:

1 . Download the latest version of Nginx 1.10.2, unzip to D:\nginx, download the Windows Service Wrapper software 1.9, copy to d:\nginx< /c4> directory and rename it to WINSW. ( click on the link above to download the software )

2. Open Notepad, copy the following to the inside, save as:D:\nginx\winsw.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>D:\nginx\nginx.exe</executable>
<logpath>D:\nginx\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p d:\nginx</startargument>
<stopargument>-p D:\nginx-s stop</stopargument>
</service>

If your directory is not the same as mine, modify it yourself!

3. Run cmd as Administrator, enter:D:\nginx\winsw.exeInstall, return, prompt installation service completed.

at this point, your nginx can be run as a Windows service, you can open the Service Manager to start, stop, modify the automatic or manual operation, etc., you can also use the Windows cmd command:net Start/stop nginx to manage. Isn't it convenient?

4. Verify that Nginx is working properly: enter in the browser localhostOr 127.0.0.1, see as shown, stating that Nginx is working properly, congratulations! Note: This method seems to have a problem on the WIN8, after restarting the computer, can not be started with the system, the reason is unknown! If you know, please tell me, thank you! Add another method:Use Microsoft's own tools to run the Nginx installation as a service.Microsoft'sThere are 2 gadgets in the Windows NT Resource kit, namely: Instsrv.exe and Srvany.exe,instsrv.exe can be used to install and remove services to the system, Srvany.exe can let the program run as a service. Srvany.exe can be used to run any EXE program as a Windows service. That is to say, Srvany is only the service shell of its registered program, this feature is very useful for us, we can let our program start with the system account, or implement the random start and start, can also hide unnecessary windows, such as the console window and so on. Of course, this is a command-line tool, but also need to modify the registry, more trouble, then we use someone else's UI gadget to implement. Click here to download this gadget to extract the files into the Nginx directory, run Srvanyui.exe, click on the upper left corner of the green plus sign, and then set up, click OK (such as), the service is created! Haha, it's easy.However, when you use Windows Service Manager to stop the Nginix service, the Access browser still sees the Web site. Look at the process and you will find that one of Nginx's processes is still running! Nginx process (according to nginx.conf configuration worker_processes 1;), the fork out of the process is clearly not stopped, the result is nginx never shut down. So completely close nginx please use the Taskkill command!        then we have to make a Stop_nginx script to handle all the actions of Nginx stop:
@echo off echo stopping nginx service ... net stop Nginx echo Kill nginx process ... taskkill/f/im Nginx.exe>nul
ps:2016.10.26 Update software download link and version!

Install Nginx as a service under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.