Run Nginx as a service in Windows platform
Batch file to run Nginx as a service in Windows platform. NSSM is the best tool to run Nginx as a service. You can follow this SO answer for more details. If due to software restrictions or any other trouble, you do not want to use any external 3rd party software then you can deploy any of these two methods. Windows Task Scheduler Windows startup shortcut Windows Task Scheduler Put this file where nginx.exe is present. Open windows task scheduler and set up the task as described in this answer to run it indefinitely. The other tabs need to be looked at as well (actions etc) - but these are the options you should specify when trying to ensure a task runs regardless of which user is logged in, and without the UAC prompts. Make the task to start daily at a certain time, through the bat file it will check whether the service is already running to avoid creating multiple nginx.exe instances. If due to some reason Nginx shuts down, within 5 minutes it will start. Windows Startup shortcut Create one shortcut of nginx.exe and put it in the startup folder of Windows. Follow this answer to find your startup location. It can be found here: or easier to access with this command in the Run Win+R prompt: Here is even more explanations of how accessing/viewing the startup folder. Nginx will run automatically whenever you log in to the system. This one is the easiest. However, it is dependent on the user profile i.e. if you are running Nginx on a server, it will run only for your user account, when you log off it stops. This is ideal for the dev environment. Run Nginx as a service in Windows platform
start.bat
|
) else (
)
stop.bat
|
) else (
)
1. Add a trigger:
Make sure to set the current date and 00:00:00 as the start time
2. Make sure the task is run as soon as possible if the start was missed:
When saving the task, you will be prompted to enter a username and password - this username and password is the user that will be used to execute the task. If you are running the task with “highest privileges” you will need to make sure this is an admin account.C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup`
shell:startup