Recently, nginx is often used. You need to start it manually every time you start it. If you want to set it to automatic execution after starting it
start nginx, find the information, try to summarize.
- System: Windows 10 home Chinese version
- Version number: 20h2
- Operating system version: 19042.685
- Nginx: version 1.18.0, only the port and root fields are configured.
- My GitHub
Windows can set the startup key by manually modifying the registry. I think it’s troublesome. I’d better find a tool. Find the toolWinSWIt can package any application and manage it as a Windows service. stayhereYou can download the compiled executable file. This version is winsw v3.0.0-alpha.7.
Winsw is used as a global tool
- newly build
myapp.xml(for more details, seefileandExamples）。
winsw install myapp.xml [options]Installation services.
winsw start myapp.xmlTurn on the service.
winsw status myapp.xmlCheck that the service is up and running.
In the process of actual operation, we found other points for attention
- Input command time parameter
myapp.xmlIt’s not necessary. If you want to omit it, let the configuration file name follow
WinSW.exeIf the name of the file is consistent, otherwise an error will be reported without the configuration file name parameter.
WinSW.exeThe file needs to be placed in the nginx installation directory, otherwise when executing the instruction, it will prompt that the nginx configuration file cannot be found.
- When there is an error, it will output a log, which is helpful for troubleshooting.
The following is an example of personal configuration steps.
Move the downloaded EXE file to the nginx directory and rename it to
winsw.exe, new profile
winsw.xml, 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>
Open the command window under the current path (enter CMD on the current file path) and execute the command:
If you succeed, the following prompt will appear:
To check whether the service has been successfully added, right-click “this computer” – > “management” – > “services and Applications” – > “services”:
Check whether the startup service is normal:
A prompt will also appear if the startup is successful. Visit the address configured by nginx to confirm whether it is valid. After confirmation, restart the computer to see if it will start automatically.