3
3

More than 1 year has passed since last update.

[mpm_winnt:notice]502エラー Apache2.4 + Laravel6 + Windows サーバー

Last updated at Posted at 2021-12-20

はじめに

Windowsサーバーで、Apache + laravelの502エラーのときの対処方法についてまとめます

環境

  • Apache2.4
  • Windows10
  • laravel6
  • PHP8.1

502のエラーログ

以下のエラーログがC:\Apache24\logs\error.logファイルで確認されていました。
windows環境では、「子プロセスの最大数は1」、この子プロセスでは、デフォルトで64のスレッドを生成可能とのことだが、これだと足りないため、再起動している?という意味かと推測しました。
windowsとApacheの組み合わせ特有のもののようです。

\Apache24\logs\error.log
#Webサーバは再起動処理を開始します。
[mpm_winnt:notice] [pid 1964:tid 760] AH00428: Parent: child process 2560 exited with status 3221225725 -- Restarting.

[mpm_winnt:notice] [pid 1964:tid 760] AH00455: Apache/2.4.51 (Win64) PHP/8.1.0 configured -- resuming normal operations

[mpm_winnt:notice] [pid 1964:tid 760] AH00456: Apache Lounge VS16 Server built: Oct  7 2021 16:27:02

[core:notice] [pid 1964:tid 760] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'

Webサーバは再起動処理を開始します。
[mpm_winnt:notice] [pid 1964:tid 760] AH00418: Parent: Created child process 3460

Webサーバは起動処理を続行します。
[mpm_winnt:notice] [pid 3460:tid 712] AH00354: Child: Starting 64 worker threads.

対処法

まず、httpd.confを修正します。
#Include conf/extra/httpd-mpm.confのシャープを外します

\Apache24\conf\httpd.conf
#Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-mpm.conf

httpd-mpm.confが有効になったため、

conf/extra/httpd-mpm.conf
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxConnectionsPerChild: maximum number of connections a server process serves
<IfModule mpm_winnt_module>
    ThreadsPerChild        150
    MaxConnectionsPerChild   0
</IfModule>

↓

< IfModule mpm_winnt_module >
ThreadsPerChild 150 #子プロセスのスレッド割り当数
MaxConnectionsPerChild 0 #0は無制限
AcceptFilter http none
AcceptFilter https none
EnableSendfile off
EnableMMAP off  
ThreadStackSize 8388608  #子プロセスそれぞれに生成されるスレッド数=PHPのメモリー確保らしい

< /IfModule >

EnableSendfile

EnableSendfileはクライアントにファイルの内容を送るとき、カーネルの sendfile サポートを使うかどうか。とあり、「運用上の問題を避けるためにこの機能を使用不可にした方が良い場合があります」と説明にはあります

EnableMMAP

EnableMMAPは「配送中にファイルの内容を読み込む必要があるときに httpd がメモリマッピングを使うかどうか」とあり、「運用上の問題を避けるためにこの機能を使用不可にした方が良い場合があります」と説明にはあります。

ちなみに、Apache2.2の場合は「Win32DisableAcceptEx」を記載するとよいです。

conf/extra/httpd-mpm.conf
<IfModule mpm_winnt_module>
### 以下辺りをコメントアウト
#ThreadsPerChild XXX
#MaxRequestsPerChild XXX

###以下を追加
Win32DisableAcceptEx
</IfModule>
3
3
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
3
3