リリースされた動的モジュールのサポートを備えたNginx 1.9.11

2月9日、nginx 1.91.11がリリースされ、 ダイナミックモジュールの待望のサポートが、 2015年4月にHabréのnginx開発者によって発表されまし






変更履歴





動的モジュールは個別の.soファイルとしてコンパイルされ、いつでもnginxの操作中にロードされます。 モジュールを追加するたびにnginxを再コンパイルする必要はありません。



ドキュメントには、すべての静的モジュールを動的に変換できるわけではないことが記載されています。 nginxソースコードにパッチを当てるモジュールに対してこのような変換を行わないでください。それらは機能しません。 また、モジュール向けのAPI呼び出しのみを使用することをお勧めします。



さらに、モジュールを特定の順序でインストールする場合、動的モジュールの場合、値ngx_module_order



を指定する必要があります。



APIは、元の静的モジュールと動的モジュールの両方で同じままでした。



動的モジュールのコンパイル



動的なモジュールとしてモジュールを追加するための新しいオプションが構成に追加されました。 --add-module



を使用する代わりに、 --add-module



--add-dynamic-module



を記述し--add-dynamic-module



。 例:



 $ ./configure --add-dynamic-module=/opt/source/ngx_my_module/
      
      





コンパイル後、バイナリモジュールが.so



(共有オブジェクト)ファイルに作成されます。 このファイルは、nginxインストールフォルダーのmodules



サブディレクトリに転送されます。







動的モジュールのロード



新しいload_module



ディレクティブを使用して、モジュールをnginxにロードできます。 例:



 load_module modules/ngx_my_module.so;
      
      





デフォルトでは、同時にロードされる動的モジュールの最大数は128に設定されています。 この値は、nginxソースコードの変数NGX_MAX_DYNAMIC_MODULES



で変更できます。



構成ファイルの変換



以下は、サードパーティモジュールngx_http_response_moduleの古いスタイルの構成の例です。



 ngx_addon_name=ngx_http_response_module HTTP_MODULES="$HTTP_MODULES ngx_http_response_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_response_module.c"
      
      





現在、 auto/module



ビルドスクリプトは多くの設定に使用されているため、新しい設定は静的モジュールと動的モジュールの両方に適しています。 同じngx_http_response_module



場合は次のようになります。



 ngx_addon_name=ngx_http_response_module if test -n "$ngx_module_link"; then ngx_module_type=HTTP ngx_module_name=ngx_http_response_module ngx_module_incs= ngx_module_deps= ngx_module_srcs="$ngx_addon_dir/ngx_http_response_module.c" ngx_module_libs= . auto/module else HTTP_MODULES="$HTTP_MODULES ngx_http_response_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_response_module.c" fi
      
      





ご覧のとおり、古いconfig



ファイルが含まれているため、nginxの古いバージョンはこのモジュールと互換性があります。



新しい構成形式の詳細については、 こちらを参照してください



複雑なモジュールの例



最後に、nginxのドキュメントは、1つのパッケージに複数のモジュールを実際に保持する複雑なモジュールの例を提供しています。 変換が少し難しくなります。 このようなモジュールは、静的モジュールとしてコンパイルする場合、いくつかのモジュールに分割する必要がありますが、動的モジュールとしてコンパイルする場合、単一の.so



ファイルを残すことができます。 COREおよびHTTPモジュールを含むngx_rtmp_moduleモジュールの例を次に示します。



変換の結果は次のとおりです。



 ngx_addon_name="ngx_rtmp_module" RTMP_CORE_MODULES=" \ ngx_rtmp_module \ ngx_rtmp_core_module \ ngx_rtmp_cmd_module \ ngx_rtmp_codec_module \ ngx_rtmp_access_module \ ngx_rtmp_record_module \ ngx_rtmp_live_module \ ngx_rtmp_play_module \ ngx_rtmp_flv_module \ ngx_rtmp_mp4_module \ ngx_rtmp_netcall_module \ ngx_rtmp_relay_module \ ngx_rtmp_exec_module \ ngx_rtmp_auto_push_module \ ngx_rtmp_notify_module \ ngx_rtmp_log_module \ ngx_rtmp_limit_module \ ngx_rtmp_hls_module \ ngx_rtmp_dash_module \ " RTMP_HTTP_MODULES=" \ ngx_rtmp_stat_module \ ngx_rtmp_control_module \ " RTMP_DEPS=" \ $ngx_addon_dir/ngx_rtmp_amf.h \ $ngx_addon_dir/ngx_rtmp_bandwidth.h \ $ngx_addon_dir/ngx_rtmp_cmd_module.h \ $ngx_addon_dir/ngx_rtmp_codec_module.h \ $ngx_addon_dir/ngx_rtmp_eval.h \ $ngx_addon_dir/ngx_rtmp.h \ $ngx_addon_dir/ngx_rtmp_version.h \ $ngx_addon_dir/ngx_rtmp_live_module.h \ $ngx_addon_dir/ngx_rtmp_netcall_module.h \ $ngx_addon_dir/ngx_rtmp_play_module.h \ $ngx_addon_dir/ngx_rtmp_record_module.h \ $ngx_addon_dir/ngx_rtmp_relay_module.h \ $ngx_addon_dir/ngx_rtmp_streams.h \ $ngx_addon_dir/ngx_rtmp_bitop.h \ $ngx_addon_dir/ngx_rtmp_proxy_protocol.h \ $ngx_addon_dir/hls/ngx_rtmp_mpegts.h \ $ngx_addon_dir/dash/ngx_rtmp_mp4.h \ " RTMP_CORE_SRCS=" \ $ngx_addon_dir/ngx_rtmp.c \ $ngx_addon_dir/ngx_rtmp_init.c \ $ngx_addon_dir/ngx_rtmp_handshake.c \ $ngx_addon_dir/ngx_rtmp_handler.c \ $ngx_addon_dir/ngx_rtmp_amf.c \ $ngx_addon_dir/ngx_rtmp_send.c \ $ngx_addon_dir/ngx_rtmp_shared.c \ $ngx_addon_dir/ngx_rtmp_eval.c \ $ngx_addon_dir/ngx_rtmp_receive.c \ $ngx_addon_dir/ngx_rtmp_core_module.c \ $ngx_addon_dir/ngx_rtmp_cmd_module.c \ $ngx_addon_dir/ngx_rtmp_codec_module.c \ $ngx_addon_dir/ngx_rtmp_access_module.c \ $ngx_addon_dir/ngx_rtmp_record_module.c \ $ngx_addon_dir/ngx_rtmp_live_module.c \ $ngx_addon_dir/ngx_rtmp_play_module.c \ $ngx_addon_dir/ngx_rtmp_flv_module.c \ $ngx_addon_dir/ngx_rtmp_mp4_module.c \ $ngx_addon_dir/ngx_rtmp_netcall_module.c \ $ngx_addon_dir/ngx_rtmp_relay_module.c \ $ngx_addon_dir/ngx_rtmp_bandwidth.c \ $ngx_addon_dir/ngx_rtmp_exec_module.c \ $ngx_addon_dir/ngx_rtmp_auto_push_module.c \ $ngx_addon_dir/ngx_rtmp_notify_module.c \ $ngx_addon_dir/ngx_rtmp_log_module.c \ $ngx_addon_dir/ngx_rtmp_limit_module.c \ $ngx_addon_dir/ngx_rtmp_bitop.c \ $ngx_addon_dir/ngx_rtmp_proxy_protocol.c \ $ngx_addon_dir/hls/ngx_rtmp_hls_module.c \ $ngx_addon_dir/dash/ngx_rtmp_dash_module.c \ $ngx_addon_dir/hls/ngx_rtmp_mpegts.c \ $ngx_addon_dir/dash/ngx_rtmp_mp4.c \ " RTMP_HTTP_SRCS=" \ $ngx_addon_dir/ngx_rtmp_stat_module.c \ $ngx_addon_dir/ngx_rtmp_control_module.c \ " ngx_module_incs=$ngx_addon_dir ngx_module_deps=$RTMP_DEPS ngx_module_libs= if [ $ngx_module_link = DYNAMIC ] ; then ngx_module_name="$RTMP_CORE_MODULES $RTMP_HTTP_MODULES" ngx_module_srcs="$RTMP_CORE_SRCS $RTMP_HTTP_SRCS" . auto/module elif [ $ngx_module_link = YES ] ; then ngx_module_type=CORE ngx_module_name=$RTMP_CORE_MODULES ngx_module_srcs=$RTMP_CORE_SRCS . auto/module ngx_module_type=HTTP ngx_module_name=$RTMP_HTTP_MODULES ngx_module_incs= ngx_module_deps= ngx_module_srcs=$RTMP_HTTP_SRCS . auto/module fi USE_OPENSSL=YES
      
      





$ngx_module_link



の値は、動的モジュールの場合はDYNAMIC



によって、静的モジュールの場合はYES



によって設定されます。 2番目のケースでは、 auto/module



ビルドスクリプトが2回呼び出されます。



PSところで、 Tengineフォークの1つは最初は動的モジュールをサポートしていましたが、このために機能が非常に必要なので、動的モジュールが作成されました。



All Articles