Home>Article>Operation and Maintenance> Configure nginx to start automatically at boot under windows

Configure nginx to start automatically at boot under windows

王林
王林 forward
2021-01-13 11:12:08 3993browse

Configure nginx to start automatically at boot under windows

Operating environment: Windows 10 Home Chinese version, version number: 20H2, operating system version: 19042.685, nginx: version 1.18.0, only the port and root fields, Origin, My are configured GitHub

(Learning video sharing:Programming video)

Solution:

Windows can set startup items by manually modifying the registry, which feels a bit troublesome , or find a tool. Find the tool WinSW , which can wrap any application and manage it as a Windows service. The compiled executable file can be downloaded here. The version used this time is WinSW v3.0.0-alpha.7.

Use WinSW as a global tool:

  • Download WinSW.exe or WinSW.zip.

  • Create new myapp.xml (see documentation and examples for more details).

  • Run winsw install myapp.xml [options] to install the service.

  • Run winsw start myapp.xml to start the service.

  • Run winsw status myapp.xml to check whether the service is up and running.

I discovered other points to note during the actual operation:

The parameter myapp.xml is not necessary when entering the command. I want to omit it and let the configuration file name match WinSW The names of the .exe files must be consistent, otherwise an error will be reported without the configuration file name parameter. The WinSW.exe file needs to be placed in the nginx installation directory, otherwise it will prompt that the nginx configuration file cannot be found when executing the instructions. When an error occurs, a log will be output. Reading the log will help troubleshoot the problem.

The following is an example of personal configuration steps.

Step 1

Move the downloaded exe file to the nginx directory, rename it to winsw.exe, create a new configuration file winsw.xml, and write the following configuration:

 nginx service Nginx This service runs Nginx.  start D:\nginx-1.18.0\nginx.exe D:\nginx-1.18.0\nginx.exe D:\nginx-1.18.0\nginx.exe -s stop   

Configure nginx to start automatically at boot under windows

Step 2

Open the command window under the current path (enter cmd on the current file path and press Enter), execute the command:

winsw install

Configure nginx to start automatically at boot under windows

The following prompt will appear if successful:

Configure nginx to start automatically at boot under windows

Check whether the service has been added successfully, right-click "This Computer"-> "Manage" -> "Services and Applications" -> "Service":

Configure nginx to start automatically at boot under windows

Step 3

Check whether the startup service is normal:

winsw start

A prompt will also appear if the startup is successful. Visit the address configured by nginx and confirm whether it is valid. After confirmation, restart the computer and see if it starts automatically.

Related recommendations:nginx tutorial

The above is the detailed content of Configure nginx to start automatically at boot under windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete