NGINX で SSL 証明書を読み込むには、http_ssl_module が必要です。SSL 証明書をインストールする前に、NGINX にこのモジュールが含まれていることを確認してください。このトピックでは、NGINX サーバーに SSL 証明書を手動でデプロイする際に発生する一般的な http_ssl_module エラーと、その解決策について説明します。
一般的なエラー
エラー 1:the "ssl" parameter requires ngx_http_ssl_module
原因
現在インストールされている NGINX に http_ssl_module がコンパイルされていません。
エラー 2:nginx: [emerg] unknown ディレクティブ "ssl" in /usr/local/nginx/conf/nginx.conf
原因
設定ファイルを変更して nginx -s reload を実行した後にこのエラーが表示される場合、現在の NGINX バージョンに http_ssl_module がコンパイルされていないことを示します。
エラー 3:./configure: error: SSL modules require the OpenSSL library
原因
OpenSSL の依存関係ライブラリが不足しています。
解決策
エラー 3 の場合は、サーバーに OpenSSL 開発ライブラリをインストールします。
エラー 1 とエラー 2 の場合は、サーバーに OpenSSL がインストールされていることを確認したうえで、http_ssl_module を有効にして NGINX を再コンパイルします。
次の例では、CentOS 8.0 64-bit、NGINX 1.14.1、OpenSSL 1.1.1k を使用します。NGINX のバージョンに応じて OpenSSL のバージョンを調整してください。
現在の NGINX バージョンに http_ssl_module が含まれているかどうかを確認します。
次のコマンドを実行して、NGINX のコンパイルパラメーターを確認します。
nginx -V | grep http_ssl_module--with-http_ssl_moduleが表示される場合、このモジュールはすでに含まれています。表示されない場合は、手動で追加する必要があります。出力例:
[root@xxx ~]# nginx -V nginx version: nginx/1.14.1 built with gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) built with OpenSSL 1.1.1 FIPS 11 Sep 2018 (running with OpenSSL 1.1.1k FIPS 25 Mar 2021) TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'OpenSSL 開発ライブラリをインストールします。
# CentOS に OpenSSL 開発ライブラリをインストールします。 sudo yum install openssl-develhttp_ssl_module を有効にして NGINX を構成し、コンパイルします。
NGINX のソースコードディレクトリに移動します。パスは、実際のソースコードのパスに置き換えてください。
cd /path/to/nginx-source-code/ # 例: cd nginx-1.14.1./configureに、nginx -Vの出力にある元の configure 引数を指定し、さらに--with-http_ssl_moduleを追加します。必要に応じて、ほかのパラメーターもカスタマイズできます。./configure <original_configure_arguments> --with-http_ssl_modulesudo makemake installは実行しないでください。既存の NGINX 設定が上書きされます。古い NGINX バイナリをバックアップし、新しいバイナリに置き換えます。
# nginx -V の出力 (--sbin-path=/usr/sbin/nginx) に基づいてパスを特定します sudo mv /usr/sbin/nginx /usr/sbin/nginx.backup # ソースディレクトリ内の objs ディレクトリから新しいバイナリをコピーします sudo cp objs/nginx /usr/sbin/nginxhttp_ssl_module がインストールされていることを確認します。
パスを実際の NGINX 実行可能ファイルのパスに置き換えてください。
/usr/sbin/nginx -V | grep http_ssl_module