处理Windows下不响应nginx关闭或reload等信号

处理Windows下不响应nginx关闭或reload等信号问题

https://serverfault.com/questions/432578/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.) 我在 Windows Server 2008 R2 (x64) 上运行 nginx 作为 Windows 服务。为此,我正在使用 Windows Service Wrapper。 (实际上,我已经遵循了本教程: 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.) 这意味着如果我停止服务,nginx 不会停止。 (我必须杀死它。)

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. 我以管理员身份运行命令,服务在 NETWORK SERVICE 用户下运行。

Any hints or similar issues? 任何提示或类似问题?

方案一:You must run reload from the same account as service run

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: 您必须从与服务运行相同的帐户运行 reload 。例如,如果您以 SYSTEM 身份运行 nginx,则可以使用 psexec 工具:

PSEXEC -s c:\nginx\nginx.exe -p c:\nginx -s reload

但是需要下载psexec工具(轻量级远程连接工具)

https://www.jianshu.com/p/9d02b90e95bb

方案二: 如果是winsw注册的nginx,调整xml

in order for it to work for me on Windows 10 with nginx 1.9.15 i had to add 为了让它在带有 nginx 1.9.15 的 Windows 10 上为我工作,我必须添加

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

下面是我的配置

<configuration>
  
  <!-- ID of the service. It should be unique accross the Windows system-->
  <id>nginx</id>
  <!-- Display name of the service -->
  <name>nginx</name>
  <!-- Service description -->
  <description>VivachekCloud nginx server</description>
  <logpath>C:\vivachekcloud\nginx</logpath>
  <logmode>roll</logmode>
  <depend></depend>
  
  <!-- Path to the executable, which should be started -->
  <executable>C:\vivachekcloud\nginx\nginx.exe</executable>
  <startargument>-p</startargument>
  <startargument>C:\vivachekcloud\nginx</startargument>
  <stopargument>-c</stopargument>
  <stopargument>C:\vivachekcloud\nginx\conf\nginx.conf</stopargument>

  <stopexecutable>C:\vivachekcloud\nginx\nginx.exe</stopexecutable>
  <stopargument>-p</stopargument>
  <stopargument>C:\vivachekcloud\nginx</stopargument>
  <stopargument>-s</stopargument>
  <stopargument>stop</stopargument>
</configuration>

方案三: 如果是nssm注册是nginx服务


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注