windows - 添加 nginx.exe 作为 Windows 系统服务(如 Apache)?

标签 windows service windows-services nginx

我将 NGINX 设置为静态内容的前端服务器,并使用 Apache 作为其他内容的后端服务器。

问题是我找不到一个合乎逻辑的答案来让我将 nginx.exe 变成 Windows 系统服务(就像我的 Apache)。

有人对此有答案吗?

最佳答案

如何使用 Windows 服务包装器

(注意:现在有更简单的替代方案 - 另请参阅下面描述的解决方案 using chocolatey package manager by sunegusing NSSM directly 来自 Adamy )

  1. 下载最新版本Windows Service Wrapper通过githubnuget .
    • 撰写本文时的当前版本是 v2.2.0
    • 由于 .NET2.0 和 .NET4.0 的 v2.x 可执行文件可用 - 其他仅按需提供。
  2. winsw-*.exe 重命名为 nginxservice.exe
    • 这是将为拥有您的 nginx 进程的进程显示的名称。
  3. 在具有相同基本名称的 exe 旁边放置一个 XML 文件,例如nginxservice.xml。内容应如下所示(验证您的 nginx 位置)。

    <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>
    
  4. 以管理员身份运行命令 nginxservice.exe install

现在您的服务中将有一个 nginx 服务! (它设置为开机自动启动;如果你想启动你的服务器,你必须手动启动服务(net start nginx)。)


正确设置nginx为Windows Service的详细说明: http://web.archive.org/web/20150819035021/http://misterdai.yougeezer.co.uk/posts/2009/10/16/nginx-windows-service/

以上博文中未包含的其他信息:

您还可以通过此 Maven 存储库找到最新版本的 Windows 服务包装器: http://repo.jenkins-ci.org

Maven + Gradle 示例:

<dependency>
    <groupId>com.sun.winsw</groupId>
    <artifactId>winsw</artifactId>
    <version>2.2.0</version>
    <classifier>bin</classifier>
    <packaging>exe</packaging>
</dependency>

<repository>
    <id>jenkinsci</id>
    <name>jenkinsci-releases</name>
    <url>http://repo.jenkins-ci.org/releases</url>
</repository>

compile "com.sun.winsw:winsw:2.2.0"

repositories {
    mavenCentral()
    maven { url http://repo.jenkins-ci.org/releases }
}

关于windows - 添加 nginx.exe 作为 Windows 系统服务(如 Apache)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10061191/

相关文章:

windows - Win32/64 应用程序是否可以从 Firebase 接收推送通知消息?

c# - 如何每 10 分钟在服务中运行一个函数?

java - 从 Java 程序中终止 Windows session

windows - 如何增加 Windows 10 的最大 GDI 对象数量?

c++ - 将一个 C 程序的输出放入另一个 C 程序的变量中

c++ - cpp 文件中是否需要 __declspec(dllexport)

c - Windows 服务 C

java - Google App Engine LogService 的开发/测试版本

c++ - 我可以通过windows服务访问itunes com界面吗?

mysql - 错误 1067 : The process terminated unexpectedly MYSQL, Windows Server 2008 R2