LoginSignup
10
10

More than 5 years have passed since last update.

Windows Server 2012 R2でNginxをサービス化する

Last updated at Posted at 2015-11-23

Nginxインストール

  • Nginxのダウンロードページ から、Stableの最新版(2015/11時点で1.8.0)のWindows用をダウンロード
  • Cドライブ直下に、ダウンロードしたzipファイルを nginx として解凍

Nginx設定

NginxのWindowsサービス化

  • winswのダウンロードページ から、winswの最新版(2015/11時点で1.18)をダウンロード
  • C:\nginxwinsw-1.18-bin.exenginxservice.exe にリネームして配置
  • 以下の内容で nginxservice.exe.config を作成
    • これを追加しない場合は、.NET Framework 3.5をインストールすればOK
    • これを追加すれば、.NET Framework 3.5をインストールしなくても動作する
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>
  • 以下の内容で nginxservice.xml を作成
    • ポイントは、stopargumentを2つに分けること
<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>nginx</description>
  <logpath>c:\nginx\logs</logpath>
  <logmode>roll</logmode>
  <depend></depend>
  <executable>c:\nginx\nginx.exe</executable>
  <startargument></startargument>
  <stopexecutable>c:\nginx\nginx.exe</stopexecutable>
  <stopargument>-s</stopargument>
  <stopargument>stop</stopargument>
</service>
  • PowerShellかコマンドプロンプトで以下を発行
    • ちなみに、アンインストールする場合は、下記の installuninstall にする
> cd c:\nginx
> .\nginxservice.exe install

参考

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10