LoginSignup
14
6

More than 5 years have passed since last update.

nginx が windows で起動しない

Posted at

nginx が windows で起動しない

windows で nginx 使いたいなと思った。
インストールして、 start nginx したら起動できると思っていたら起動しなかったので、その対処方法を記載。

nginx をインストール

  1. ここから Stable Versionnginx/Windows-x.x.x をダウンロード。
  2. ZIPファイル( nginx-x.x.x.zip )を解答して Cドライブ直下に移動( c:\nginx
  3. コマンドプロンプトで c:\nginx に移動して start nginx
   cd c:\nginx
   start nginx

起動しない

コマンドプロンプトが表示されるが、一瞬で落ちる。
コマンドプロンプトを 管理者として実行 して start nginx しても変わらず。

nginx のログを確認してみた

\nginx\logs\error.log を確認すると以下のエラーが発生していた。

An attempt was made to access a socket in a way forbidden by its access permissions

他プログラムによって nginx で使用するポート番号が使用されている場合に発生するみたい。
ちなみに設定しているポート番号はデフォルトで 80。

誰が使用しているのか確認

C:\Users\xxx>netstat -ano |find /i "listening"|find /i ":80"
  TCP         0.0.0.0:80             0.0.0.0:0              LISTENING       4
  TCP         [::]:80                [::]:0                 LISTENING       4
C:\Users\xxx>tasklist /FI "PID eq 4"
イメージ名                     PID セッション名     セッション# メモリ使用量
========================= ======== ================ =========== ============
System                           4 Services                   0      4,868 K

NT Kernel & System が使用しているみたい。

nginx の使用するポート番号を変更

80 は使用されていることがわかったので、 nginx の使用するポート番号を 8080 に変更。

  1. nginx\conf\nginx.conf を開く
  2. ポート番号変更
   server {
       listen       8080;
       server_name  localhost;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {
           root   html;
           index  index.html index.htm;
       }

※ listen の値を 80 → 8080 に変更。

nginx を起動

cd c:\nginx
start nginx

無事起動。

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