I am trying to run nginx (reverse proxy) as a windows service so that it's possible to proxy a request even when a user is not connected.
I searched a lot around and found winsw that should create a service from an .exe file (such as nginx).
i found many tutorials online saying to create an xml file as following
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>c:\nginx\nginx.exe</executable>
<logpath>c:\nginx\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p c:\nginx</startargument>
<stopargument>-p c:\nginx -s stop</stopargument>
</service>
(i have nginx.exe in a folder called nginx under c: o the paths are correct).
Now the problem is that the service is created but i can't seem to make it start, every time i try to start it a windows pops up saying
Error 1053: The service didn't respond to the start or control request in a timely fashion
Does anyone know how can i fix this or a different way to run nginx as a window service?
Just stumbled here and managed to get things working with this free open source alternative: https://nssm.cc/
It basically is just a GUI to help you create a service. Steps I used:
You should be good to go from then on.
NSSM is very nice, but there is another alternative: The PowerShell Cmdlet New-Service
Here is just a simple example:
$params = @{
Name = "MyService"
BinaryPathName = "path/to/exe"
DisplayName = "My Service"
StartupType = "Automatic"
Description = "Description of my service"
}
New-Service @params
I found other solution other than NSSM . That is Windows Service Wrapper and the following are the instructions:
Download the latest version of Windows Service Wrapper via github .
Rename winsw-xxxx.exe to something like nginxservice.exe.
<service> <id>nginx</id> <name>nginx</name> <description>nginx</description> <executable>c:\\nginx\\nginx.exe</executable> <logpath>c:\\nginx\\</logpath> <logmode>roll</logmode> <depend></depend> <startargument>-p</startargument> <startargument>c:\\nginx</startargument> <stopexecutable>c:\\nginx\\nginx.exe</stopexecutable> <stopargument>-p</stopargument> <stopargument>c:\\nginx</stopargument> <stopargument>-s</stopargument> <stopargument>stop</stopargument> </service>
You can find up to date details about the configuration on the config GitHub page and a generic example showing all possible options here .
The Above answer was taken from a post .
我找到了NSSM (Non-Sucking Service Manager):一个程序完全符合我的要求,而且设置起来要容易得多。
As told in other answers 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
Create one shortcut of nginx.exe and put it in the startup folder of Windows.
Follow this answer to find your startup location.
You'll need this for winsw
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>c:\...\nginx.exe</executable>
<logpath>...</logpath>
<logmode>roll</logmode>
<stopexecutable>c:\nginx\nginx-1.14.0\nginx.exe</stopexecutable>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument>
</service>
You will need an <executable>
assuming you are using the nginx.conf hence don't need any starting up arguments and also a <stopexecutable>
and <stopargument>
s (to emlate nginx -s stop
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.