Nginx installation and environment configuration under Windows (running nginx as a service)

Nginx installation and environment configuration under Windows (running nginx as a service)

The first and most important step is how to install the Ngnix service in Windows environment?

Go to http://nginx.org/en/download.html to download the appropriate version. Of course, the MainLine version is recommended. After downloading, unzip it and double-click Ngnix.exe to run it (the default port is 80). If you have deployed IIS on a Windows server, be sure to change the default port, otherwise there will be a conflict.

If everything is normal, access the local address + port number and you will see an interface like this:

We cannot assume that everything is fine at this point. In a Windows server environment, simply running a service as a process is considered unstable. Secondly, if the process is recycled or crashes, it is difficult to find related logs and error messages, which causes trouble for debugging. Therefore, we tend to package the process as a Windows service, which will have better robustness.

But the default Ngnix does not support Windows services (the reason has been explained in the introduction, Ngnix for Windows is only considered a test version), so we have to find some other ways to install Ngnix as a Windows service.

Common methods include instsrv/servany and FireDaemon, but these methods have their own problems. For example, instsrv/servany will generate a new Ngnix.exe process when the service is restarted, stopped/started. After FireDaemon is started, it will bring up a secondary process by default. The reasons and background have been explained in detail in the Defonds blog.

Therefore, we recommend using Windows Service Wrapper to install the Ngnix service. This is an open source project on GitHub. It can install any exe, bat and other files as Windows services. You can also download its source code on GitHub.

Due to the need to circumvent the firewall and other reasons, not everyone can download the binary version. Here is a convenient download. (Version 1.9)

https://www.jb51.net/softs/645594.html

After the download is complete, kill the ngnix process you originally ran, change winsw.exe to any name and create an xml file as the configuration. Of course, the name should be consistent with the exe name.

The configuration code is as follows:

<service> 
 <id>nginx</id> 
 <name>nginx</name> 
 <description>nginx</description> 
 <executable>D:\Soft\Nginx\nginx-1.9.15\nginx-1.9.15\nginx.exe</executable> 
 <logpath>D:\Soft\Log\</logpath> 
 <logmode>roll</logmode> 
 <depend></depend> 
 <startargument>-p D:\Soft\Nginx\nginx-1.9.15\nginx-1.9.15</startargument> 
 <stopargument>-p D:\Soft\Nginx\nginx-1.9.15\nginx-1.9.15 -s stop</stopargument> 
</service>

Modify the configuration of executable, logpath, startargument, stopargument according to your needs.

Then go to your winsw.exe directory and execute the winsw.exe install command (to uninstall, use winsw.exe uninstall).

If everything goes well, you will see your Ngnix service appear in the service list. Start the service and you can see the welcome message shown above. This means that your Ngnix installation is successful and you can use it.

<<:  Detailed explanation of Vue form binding and components

>>:  MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)

Recommend

How to use html2canvas to convert HTML code into images

Convert code to image using html2canvas is a very...

JavaScript Design Pattern Command Pattern

The command pattern is a behavioral design patter...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

Two ways to declare private variables in JavaScript

Preface JavaScript is not like other languages ​​...

MySQL 8.0.15 installation tutorial for Windows 64-bit

First go to the official website to download and ...

Mysql5.6.36 script compilation, installation and initialization tutorial

Overview This article is a script for automatical...

How to install binary MySQL on Linux and crack MySQL password

1. Make sure the system has the required libaio s...

How to install OpenSuse on virtualbox

The virtual machine is installed on the host mach...

Detailed steps to download Tomcat and put it on Linux

If you have just come into contact with Linux, th...

Troubleshooting the reasons why MySQL deleted records do not take effect

A record of an online MySQL transaction problem L...

How to use webpack and rollup to package component libraries

Preface I made a loading style component before. ...

Simple implementation of mini-vue rendering

Table of contents Preface Target first step: Step...

Tutorial on how to quickly deploy a Nebula Graph cluster using Docker swarm

1. Introduction This article describes how to use...