将 nginx.exe 添加为 Windows 系统服务(如 Apache)? [英] Add nginx.exe as Windows system service (like Apache)?

查看:22
本文介绍了将 nginx.exe 添加为 Windows 系统服务(如 Apache)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I set up NGINX as a front end server for static content and I use Apache as a back-end server for other thing.

问题是我找不到允许我使 nginx.exe 成为 Windows 系统服务(如我的 Apache)的合乎逻辑的答案.

The thing is I can't find a logical answer that allows me to make nginx.exe a Windows system service (like my Apache).

有人遇到过这个问题的答案吗?

Any come across an answer to this?

推荐答案

如何使用 Windows Service Wrapper

(注意:现在有更简单的替代方案 - 另请参阅下面描述的解决方案使用巧克力包管理器,作者:suneg 和直接使用 NSSM 来自 Adamy)

(Note: There are easier alternatives by now - see also solutions described here below using chocolatey package manager by suneg and using NSSM directly from Adamy)

  1. 通过 Windows Service Wrapper.com/kohsuke/winsw/releases" rel="nofollow noreferrer">github 或 nuget.
    • 撰写本文时的当前版本是 v2.2.0
    • 由于适用于 .NET2.0 和 .NET4.0 的 v2.x 可执行文件可用 - 其他仅按需提供.
  1. Download the latest version of Windows Service Wrapper via github or nuget.
    • Current version as of this writing is v2.2.0
    • Since v2.x executables for .NET2.0 and .NET4.0 are available - others only on demand.
  • 这是将为拥有您的 nginx 进程的进程显示的名称.

在具有相同基本名称的 exe 旁边放置一个 XML 文件,例如nginxservice.xml.内容应如下所示(请验证您的 nginx 位置).

Place an XML file next to the exe with the same base name, e.g. nginxservice.xml. The contents should be like below (verify your nginx location).

<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>nginx</description>
  <executable>c:
ginx
ginx.exe</executable>
  <logpath>c:
ginx</logpath>
  <logmode>roll</logmode>
  <depend></depend>
  <startargument>-p</startargument>
  <startargument>c:
ginx</startargument>
  <stopexecutable>c:
ginx
ginx.exe</stopexecutable>
  <stopargument>-p</stopargument>
  <stopargument>c:
ginx</stopargument>
  <stopargument>-s</stopargument>
  <stopargument>stop</stopargument>
</service>

  • 您可以在 配置 github 页面,一个显示所有可能选项的通用示例 此处安装指南.
    • You can find up to date details about the configuration on the config github page, a generic example showing all possible options here and an installation guide.
    • 您现在将在您的服务中拥有一个 nginx 服务!(设置为开机自动启动;如果你想启动你的服务器,你必须手动启动服务(net start nginx).)

      You will now have an nginx service in your Services! (It is set to start automatically on boot; if you want to start your server, you must manually start the service (net start nginx).)

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

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

      Additional info not contained in above blog post:

      您也可以通过此 Maven 存储库找到最新版本的 Windows Service Wrapper:http://repo.jenkins-ci.org

      You can find the latest version of the Windows Service Wrapper also via this Maven Repository: http://repo.jenkins-ci.org

      Maven + Gradle 示例:

      Examples for 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 }
      }
      

      这篇关于将 nginx.exe 添加为 Windows 系统服务(如 Apache)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆