16

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?

1
  • A ProcMon trace should be able to help identifying the issue. If you could download Process Monitor application, run it, start the tracing, repeat the steps you done before (so you would reproduce the Access Denied error), stop the trace, save it as PML file (All Events), and share the file with us, we might be able to provide the solution. Mar 21, 2016 at 9:50

9 Answers 9

6

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

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.

2
  • where to find this xml? Context is important!
    – Roel
    Jun 20, 2019 at 12:32
  • @roel it's part of Windows Service Wrapper, not nginx May 24, 2022 at 15:11
2

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
1

in order for it to work for me on Windows 10 with nginx 1.9.15 i had to add

-p c:\nginx 

in the stop arguments

<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>
0

A couple things to try:

  1. Why run in the NETWORK SERVICE account? Try with the default for all services, LocalSystem.

  2. Follow this tutorial to try another wrapper, AlwaysUp. If it works then you may be facing a problem with Windows Service Wrapper.

Please report what you find.

0
  1. Open cmd as Administrator.
  2. Then cd to the folder where nginx is located and then run the commands:

cmd (as Administrator)

cd E:\apath\nginx\nginx.exe
nginx -s reload
0

This may not be the best way, but works.

I tried reloading after adding new config, but could not reload nginx.

But we can kill current nginx proceses forcefully and start again.

let's first find the current nginx pid

tasklist /fi "imagename eq nginx.exe"

sample response

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
nginx.exe                    12644 Console                   13        108 K
nginx.exe                     1132 Console                   13      2,392 K

Now let's kill these two PID

taskkill /PID 12644 /f
taskkill /PID 1132 /f

Now let's start the nginx again

start nginx

Make sure you are on the nginx installed folder. :) while running the last command on Command Prompt.

0

You have to add additional permissions to the access.log

  1. Click "Properties" of your access log file in the file explore
  2. Choose "Security" Tab
  3. Click "Edit" button and choose "Users" which you want to run for nginx
  4. Allow "Full control"
  5. Click "OK" button
-1
  1. Open cmd as Administrator.
  2. Then cd to the folder where nginx is located and then run the commands:

cmd (as Administrator)

cd E:\apath\nginx\nginx.exe
start nginx
1
  • This is a blatant copy of an existing answer, which was already incorrect because the OP stated that they are running the command as an administrator.
    – Sam Erde
    Oct 10, 2020 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .