nginx stop/reload on windows failed for Access is denied
I am running nginx on Windows Server 2008 R2 (x64) as a windows service. I am using Windows Service Wrapper for that. (Actually, I have followed this tutorial: http://mercurial.selenic.com/wiki/HgServeNginxWindows.)
The service is running ok. However, the server does not process the signals (e.g. stop / reload).
This means if I stop the service, nginx is not stopped. (I have to kill it.)
And when I want to reload the configuration from command line:
C:\Users\Administrator>E:\apath\nginx\nginx.exe -p E:\apath\nginx -c E:\apath\nginx.conf -s reload
It outputs:
nginx: [error] OpenEvent("Global\ngx_reload_4268") failed (5: Access is denied)
I am running the command as administrator and the service is running under NETWORK SERVICE user.
Any hints or similar issues?
Solution 1:
You must run reload
from the same account as service run. For example, if you run your nginx as SYSTEM, then you can use psexec
tool:
PSEXEC -s c:\nginx\nginx.exe -p c:\nginx -s reload
Solution 2:
I run my nginx-service under LOCAL SYSTEM and I use following xml configuration:
<service>
<id>nginx-service</id>
<name>nginx-service</name>
<description>nginx-service</description>
<executable>c:\nginx\nginx.exe</executable>
<logpath>c:\nginx\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-pc:\nginx</startargument>
<stopexecutable>c:\nginx\nginx.exe</stopexecutable>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument>
</service>
I'm using Windows Service Wrapper 1.18 and this configuration works for me. Nginx processes should be stopped gracefully now. Good luck.
Solution 3:
Based on your output, I assume that you are on a Windows box. I encountered exactly the same problem. I solved my problem by finding out that the Nginx was managed by NSSM. I installed the Nginx via chocolatey and it treated NSSM as a dependency.
Launch an administrative Command Prompt and run the following.
nssm restart nginx