执行nginx exe文件夹与-s reload args领事模板Windows

wwodge7n  于 7个月前  发布在  Nginx
关注(0)|答案(2)|浏览(92)

我正在使用领事模板V0.19.0 * for windows*,用于渲染nginx负载平衡配置。它正按预期工作。
现在我想要consur模板,在一个带有args(-s reload)的文件夹中执行nginx exe,如下所示:-

案例1:

template {
source = "Template/template.ctmpl"
destination = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\conf\\nginx.conf"
command = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\nginx -s reload"
command_timeout = "60s"
}

字符串
但它会抛出类似以下的错误:“无法从“模板/模板.ctmpl”中执行命令“F:\IDE\Visual Studio集合\Web服务器\nginx-1.12.0\nginx-1.12.0\nginx. exe”=>“F:\IDE\Visual Studio集合\Web服务器\nginx-1.12.0\nginx-1.12.0\conf\nginx. conf”:子级:可执行文件:“F:IDEVisual”:文件不存在”。

**案例2:-**目前,我已经通过将nginx作为服务(使用nssm)来实现这一点,并给出如下命令:

command = "powershell restart-service nginx"


而不是在完整路径后加上“-s reload”。
但为此,必须使nginx作为一个服务使用的应用程序,如nsm。
我想知道,有没有办法告诉consur模板config中的command属性,“在文件夹中执行nginx exe,就像在Case 1中一样”?
谢谢.

7y4bm7vi

7y4bm7vi1#

试试这个

template {
source = "Template/template.ctmpl"
destination = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\conf\\nginx.conf"
command = "\"F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\nginx\" -s reload"
command_timeout = "60s"
}

字符串
如果这不起作用,请尝试以下选项,也用于命令

command = "\"F:/IDE/Visual Studio Collection/Web Servers/nginx-
1.12.0/nginx-1.12.0/nginx\" -s reload"


command = "\"F:\\\\IDE\\\\Visual Studio Collection\\\\Web Servers\\\\nginx-
1.12.0\\\\nginx-1.12.0\\\\nginx\" -s reload"

编辑-1

所以根据讨论,似乎你的nginx配置有一个相对的基于文件夹的配置。当nginx从一个文件夹启动时,它也需要从同一个文件夹重新加载。所以你需要更改到文件夹,然后执行reload命令。你应该尝试的两种格式是

command="cd '<NGINX FOLDER PATH>' && nginx -s reload"


command="cmd /k 'cd \'<NGINX FOLDER PATH>\' && nginx -s reload'"

wvmv3b1j

wvmv3b1j2#

我也有同样的问题child:exec:“C:nginx”:file does not exist”。
没有解决方案以上也没有其他在网上不工作。
但我终于找到了解决办法。
使用choco install nginx-service 1.24.0(安装nginx和nsm,手动安装可以工作,我认为但这是更简单的方式)
带有启动bat命令的模板,其中是nginx服务

template {
  source = "c:\\consul\\template.ctmpl"
  destination = "C:\\tools\\nginx\\conf.d\\nginx-location.conf"
  wait {
    min = "2s"
    max = "13s"
  }
 command = "C:\\consul\\test.bat"
 command_timeout = "60s"
}

字符串
test.bat

powershell restart-service nginx-service


另外,我的整个解决方案是为同一任务的单个容器寻址(反向代理),这些容器在连接到consul的nomad集群中。现在终于工作了。

相关问题