How to quickly install nginx under Windows and configure it to start automatically

How to quickly install nginx under Windows and configure it to start automatically

Nginx is already a commonly used tool in our daily development. Simple and fast installation and configuration greatly reduces the time wasted on deployment and debugging. This article introduces nginx正常安裝流程,以及開機自啟動配置. Remember to collect it in advance. Don't regret it when you need it~

Stop talking nonsense and get in the car!

insert image description here

1. Nginx installation and startup process under Windows system:

這是我們在正常環境中,Windows下Nginx的安裝及啟動方式

1. Download the corresponding version from the nginx official website (http://nginx.org/en/download.html). I put it in D:\work\nginx\ path for decompression.

2. Start Nginx in two ways:

Just double-click nginx.exe, you will see a black pop-up window flash by, and the startup is complete. Open the cmd command window, switch to the nginx directory, enter the command nginx.exe or start nginx, and press Enter.

3. Check whether nginx is started successfully.

Directly enter the URL http://localhost:80 in the browser address bar and press Enter. The following page will appear, indicating that the startup is successful.

insert image description here

You can also enter the command tasklist /fi "imagename eq nginx.exe" in the cmd command window. If the following result appears, it means the startup is successful.

insert image description here

4. Shut down nginx

If you use the cmd command window to start nginx,關閉掉cmd窗口will not end the nginx process. You can use two methods to shut down nginx

Enter the nginx command nginx -s stop (quickly shut down nginx) or nginx -s quit (completely shut down nginx and keep the operation log) on ​​the cmd command line.

However, in our actual deployment process, the machine often crashes. Once the machine crashes and the nginx service is restarted, it will be gone. Do手動重新打開? That doesn't exist. If I had that much time, wouldn't it be nice for me to go and touch some fish?

Therefore, it is particularly important for nginx to start automatically at boot.

2. Set Nginx to start automatically at boot

We use the Windows Service Wrapper gadget to convert Nginx into a Windows service, and configure automatic startup in the service center so that Windows automatically starts the Nginx service when it boots up.

1. Download the self-starting tool

Tool download URL: https://github.com/winsw/winsw/releases

As shown below, it is the tool file for windows32位和64位

insert image description here

The above github requires external network access for faster speed. For students who don’t have external network, I have downloaded it for you. Please download it by yourself~

32-bit: Link: https://pan.baidu.com/s/1M5A5pWzQopqAsNRUxUL_AA Extraction code: a6kf

64-bit: Link: https://pan.baidu.com/s/1Qv00LQOiW_CTyIHqY1wzlA Extraction code: cay8

2. Install the auto-start tool

Step 1 : After downloading, put the tool into the Nginx installation directory and重命名為nginx-service.exe ;

Step 2 : Create a new service log folder server-logs folder in the nginx installation directory to store nginx service related logs.

Step 3 : Create a new nginx-service.xml file in this directory and write the configuration information. After the configuration is completed, you can use this to register Nginx as a Windows service.

The file configuration content is as follows: the key points include three, log file location, startup command, and shutdown command; my nginx directory is: D:\work\nginx\nginx-1.18.0 , students can make corresponding modifications according to their own directories.

<!-- nginx-service.xml -->
<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>nginx</description>
    <logpath>D:\work\nginx\nginx-1.18.0\server-logs\</logpath>
    <logmode>roll</logmode>
    <depend></depend>
    <executable>D:\work\nginx\nginx-1.18.0\nginx.exe</executable>
    <stopexecutable>D:\work\nginx\nginx-1.18.0\nginx.exe -s stop</stopexecutable>
</service>

3. Add nginx to the windows service

After the above content is configured, run the command as an administrator in the nginx installation directory: .\nginx-service.exe install to successfully register it as a Windows service. At this time we can view the nginx service in the services of Windows Task Manager.

insert image description here


The subsequent modification process of Windows services should be clear to the students. Just change the startup mode to automatic;

insert image description here


Then start the nginx service

insert image description here


After startup, check whether the startup is successful through http://localhost:80 or command tasklist /fi "imagename eq nginx.exe"

insert image description here

Appendix: Other commands of the tool

Effect Order
Register system service command nginx-service.exe install
Delete registered system service command nginx-service.exe uninstall
Stop the corresponding system service command nginx-service.exe stop
Start the corresponding system service command nginx-service.exe start

This is the end of this article about quickly installing nginx under Windows and configuring it to start automatically at boot. For more relevant content about nginx starting automatically at boot, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of the solution to Nginx startup in Centos7
  • Install and configure Nginx on CentOS 7
  • Detailed explanation of configuring Nginx auto-start based on CentOS 7
  • Example of implementing nginx self-starting script under centos/rhel

<<:  Detailed explanation of the transition attribute of simple CSS animation

>>:  Detailed explanation of MySQL joint query optimization mechanism

Recommend

Native JS music player

This article example shares the specific code of ...

Specific steps for Vue browser to return monitoring

Preface When sharing a page, you hope to click th...

Solution to the Multiple primary key defined error in MySQL

There are two ways to create a primary key: creat...

Tutorial on Migrating Projects from MYSQL to MARIADB

Prepare the database (MySQL). If you already have...

How to use linux commands to convert and splice audio formats

Install FFmpeg flac eric@ray:~$ sudo apt install ...

Detailed explanation of JavaScript axios installation and packaging case

1. Download the axios plugin cnpm install axios -...

Summary of the minesweeping project implemented in JS

This article shares the summary of the JS mineswe...

Tutorial on how to quickly deploy clickhouse using docker-compose

ClickHouse is an open source column-oriented DBMS...

vue-element-admin global loading waiting

Recent requirements: Global loading, all interfac...

How to center your HTML button

How to center your HTML button itself? This is ea...

Using radial gradient in CSS to achieve card effect

A few days ago, a colleague received a points mal...

Implementing a shopping cart with native JavaScript

This article shares the specific code of JavaScri...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...