Add nginx.exe as Windows system service (like Apache)?

前端 未结 9 1091
面向向阳花
面向向阳花 2020-12-04 07:08

I set up NGINX as a front end server for static content and I use Apache as a back-end server for other thing.

The thing is I can\'t find a logical answer that allow

9条回答
  •  情书的邮戳
    2020-12-04 07:26

    NSSM is the best tool to run Nginx as a service.
    If you do not want to use any external 3rd party software then you can implement any of these two methods.

    • Windows Task Scheduler
    • Windows startup shortcut

    Windows Task Scheduler

    • As mentioned in this answer prepare one start.bat file.
    • 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.
    • Do not forget to run this task as the highest privilege with the system account, more details can be found here.
    • 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.

    • Nginx will run automatically whenever you log in to the system.
    • This one is the easiest. However, it is dependent on 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 dev environment.

提交回复
热议问题