Configure nginx to start automatically at boot under windows

王林
Release: 2021-01-13 11:12:08
forward
4147 people have browsed it

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:

<service>
  <id>nginx service</id>
  <name>Nginx</name>
  <description>This service runs Nginx.</description>
  <env name="NGINX_COMIC" value="%BASE%" />
  <prestart>start D:\nginx-1.18.0\nginx.exe</prestart>
  <executable>D:\nginx-1.18.0\nginx.exe</executable>
  <prestop>D:\nginx-1.18.0\nginx.exe -s stop</prestop>
  <log mode="roll" />
  <onfailure action="none" />
</service>
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template