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

Web Design: The Accurate Location and Use of Massive Materials

Three times of memorization allows you to remembe...

Nodejs error handling process record

This article takes the connection error ECONNREFU...

Implementation of Vue 3.x project based on Vite2.x

Creating a Vue 3.x Project npm init @vitejs/app m...

Practical MySQL + PostgreSQL batch insert update insertOrUpdate

Table of contents 1. Baidu Encyclopedia 1. MySQL ...

Understanding and application scenarios of enumeration types in TypeScript

Table of contents 1. What is 2. Use Numeric Enume...

Detailed explanation of the pitfalls of MySQL 8.0

I updated MySQL 8.0 today. The first problem: Nav...

Why is the scroll bar on the web page set on the right?

Why are the scroll bars of the browsers and word ...

CSS tips for implementing Chrome tab bar

This time let’s look at a navigation bar layout w...

Vue implements online preview of PDF files (using pdf.js/iframe/embed)

Preface I am currently working on a high-quality ...

Solve the problem that IN subquery in MySQL will cause the index to be unusable

Today I saw a case study on MySQL IN subquery opt...

MySQL 8.0.12 installation graphic tutorial

MySQL8.0.12 installation tutorial, share with eve...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

Centos7.5 configuration java environment installation tomcat explanation

Tomcat is a web server software based on Java lan...