Add nginx.exe as Windows system service (like Apac

2019-01-12 17:37发布

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 allows me to make nginx.exe a Windows system service (like my Apache).

Any come across an answer to this?

9条回答
霸刀☆藐视天下
2楼-- · 2019-01-12 18:06

Download zip file from here.

Extract nginx-service.exe from winginx\build and run it.

查看更多
Evening l夕情丶
3楼-- · 2019-01-12 18:09

The easiest way I've found, was using the Chocolatey package manager.

Once Chocolatey is installed, you open an administrative prompt and type:

choco install nginx

You now have a Windows service named 'nginx' running.

查看更多
不美不萌又怎样
4楼-- · 2019-01-12 18:10

You can using start.bat and stop.bat to realize the same effect.

start.bat

@ECHO OFF
REM Start Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF NOT "%ERRORLEVEL%"=="0" (
   REM Nginx is NOT running, so start it
   c:
   cd \nginx
   start nginx.exe
   ECHO Nginx started.
) else (
   ECHO Nginx is already running.
)

stop.bat

@ECHO OFF
REM Stop Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF "%ERRORLEVEL%"=="0" (
   REM Nginx is currently running, so quit it
   c:
   cd \nginx
   nginx.exe -s quit
   ECHO Nginx quit issued.
) else (
   ECHO Nginx is not currently running.
)
查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-12 18:18

Official nginx wiki referes on winginx for this purpose. It builds exe-installer in linux environment. Process looks like this:

sudo apt-get install nsis make
wget https://github.com/InvGate/winginx/archive/master.zip
unzip master.zip
cd winginx-master/
make
ls -lh ./build/nginx-service.exe

To get actual versions you should specify them in Makefile.

查看更多
仙女界的扛把子
6楼-- · 2019-01-12 18:20

SC.EXE will only work for executables that already support the Windows Services API and can respond properly to start and stop requests from the Services Control Manager (SCM). Other regular applications, not specifically written as a service, will simply fail to start (usually with error 1053)...

For those exe's, you need a "service wrapper" -- a small utility that can accept the start/stop commands from the SCM and run/terminate your application accordingly. Microsoft provides Srvany (which is free yet very basic), but there are several other free and commercial alternatives.

BTW, you should check out this guide showing how to run Nginix as a service, especially step 7 which discusses how to stop Nginix properly. Not every wrapper will support that functionality (Srvany doesn't)...

查看更多
ら.Afraid
7楼-- · 2019-01-12 18:21

Download NSSM form http://nssm.cc/download . "Run %NSSM_HOME%\nssm.exe install “Nginx”"

Select the Nginx executable in the NSSM dialog, then OK. Go to Services and start the new created service "Nginx", done.

查看更多
登录 后发表回答