HttpSslModuleJa

= Synopsis = このモジュールにより HTTPS のサポートが有効になります.

このモジュールはクライアント証明書のチェックをサポートしますが、制約が二点あります.


 * it's not possible to assign a Certificate Revocation List for Nginx versions below 0.8.7.
 * if you have a chain of certificates &mdash; by having intermediate certificates between the server certificate and the CA root certificate &mdash; they're not specified separately like you would do for Apache. Instead you'll need to concatenate all the certificates, starting with the server certificate, and going deeper in the chain running through all the intermediate certificates. This can be done with "cat chain.crt >> mysite.com.crt" on the command line. Once this is done there's no further use for all the intermediate certificates in what Nginx is concerned. You'll indicate in the Nginx configuration the file with all the (concatenated) certificates.

By default the module is not built, it is necessary to state it explicitly: give the --with-http_ssl_module parameter to ./configure. Building this module requires the OpenSSL library and respective include files; quite often the library and include files live in separate packages in your platform, the later being named like libssl-dev or similar.

以下に設定例を示します. CPU負荷を低減するため、実行するワーカプロセスは 1 プロセスに留め、keep-alive コネクションを有効にすることを推奨します.

worker_processes 1; http { server { listen              443; ssl                 on; ssl_certificate     /usr/local/nginx/conf/cert.pem; ssl_certificate_key /usr/local/nginx/conf/cert.key; keepalive_timeout   70; } }

When using a chain of certificates, just append the extra certificates to your .crt file (cert.pem in the example). The server certificate needs to be the first on the file, otherwise you'll get a mismatch between private and public keys.

Nginx バージョン 0.7.14 以降では、SSL を有効にする方法として、`listen` ディレクティブ内で `ssl` パラメータを用いる方法が推奨されるようになりました. server { listen 443 default_server ssl; ssl_certificate     /usr/local/nginx/conf/cert.pem; ssl_certificate_key /usr/local/nginx/conf/cert.key; ... }

証明書の生成
以下の openssl コマンドを実行することで、プライベートな証明書（オレオレ証明書）を生成することができます.

First change directory to where you want to create the certificate and private key, for example: $ cd /usr/local/nginx/conf Now create the server private key, you'll be asked for a passphrase: $ openssl genrsa -des3 -out server.key 1024 Create the Certificate Signing Request (CSR): $ openssl req -new -key server.key -out server.csr Remove the necessity of entering a passphrase for starting up nginx with SSL using the above private key: $ cp server.key server.key.org $ openssl rsa -in server.key.org -out server.key Finally sign the certificate using the above private key and CSR: $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Update Nginx configuration by including the newly signed certificate and private key:

server { server_name YOUR_DOMAINNAME_HERE; listen 443; ssl on; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; }

Restart Nginx.

Now we're ready to access the above host using:

https://YOUR_DOMAINNAME_HERE

複数サーバに対してワイルドカード証明書を用いる
In some instances you may wish to provide a number of secure subdomains amongst unsecured ones, and possibly share resources across both HTTP and HTTPS subdomains. To do this one would require a wildcard subdomain, for example *.nginx.org. An example configuration follows which shows how to configure a standard www subdomain, a secured subdomain, and share images across both subdomains using a third.

When using a configuration like this it's more efficient memory wise to place the certificate file containing the certificate(s) for all domain names and the corresponding private key file directives in a http context, such that it's inherited by all active servers/virtual hosts: ssl_certificate     common.crt; ssl_certificate_key common.key;

server { listen          80; server_name     www.nginx.org; ... }

server { listen          443 default_server ssl; server_name     secure.nginx.org; ... }

server { listen          80; listen          443; server_name     images.nginx.org; ... }

= ディレクティブ =

ssl


Enables HTTPS for a server. (Note that since nginx version 0.7.14, the standard way to enable SSL is through the listen directive.)

ssl_certificate


This directive specifies the file containing the certificate, in PEM format, for this virtual host. This file can contain also other certificates and the server private key. Since version 0.6.7 the file path is relative to the directory where nginx main configuration file, nginx.conf, resides.

ssl_certificate_key


This directive specifies the file containing the private key, in PEM format, for this virtual host. Since version 0.6.7 the file path is relative to the directory where nginx main configuration file, nginx.conf, resides.

ssl_ciphers


This directive describes the list of cipher suites the server supports for establishing a secure connection. Cipher suites are specified in the OpenSSL cipherlist format, for example:

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

Since nginx version 1.0.5, the default ciphers are: ssl_ciphers HIGH:!aNULL:!MD5;

The complete cipherlist supported by the currently installed version of OpenSSL in your platform can be obtained by issuing the command: openssl ciphers

ssl_client_certificate


This directive specifies the file containing the CA (root) certificate, in PEM format, that is used for validating client certificates.

ssl_crl


This directive, introduced in Nginx version 0.8.7, specifies the filename of a Certificate Revocation List, in PEM format, which is used to check the revocation status of certificates.

ssl_dhparam


This directive specifies a file containing Diffie-Hellman key agreement protocol cryptographic parameters, in PEM format, utilized for exchanging session keys between server and client.

ssl_prefer_server_ciphers


The server requires that the cipher suite list for protocols SSLv3 and TLSv1 are to be preferred over the client supported cipher suite list.

ssl_protocols


This directive enables the protocol versions specified.

ssl_verify_client


This directive enables the verification of the client identity. Parameter 'optional' checks the client identity using its certificate in case it was made available to the server. (Was 'ask' before 0.8.7 and 0.7.63)

ssl_verify_depth


This directive sets how deep the server should go in the client provided certificate chain in order to verify the client identity.

ssl_session_cache


このディレクティブは、SSL セッションを格納するキャッシュの形式とサイズを設定します. キャッシュの形式は次の値をとります:

次のようにして、builtin と shared を同時に用いることができます.
 * off -- Hard off: nginx はクライアントに対して、セッションの再利用を行わないことを明示的に通知します.
 * none -- Soft off: nginx はクライアントに対して、セッションの再利用は可能だが nginx 自体は再利用を行わないことを通知します. This is workaround for some mail clients as ssl_session_cache may be used in mail proxy as well as in HTTP server.
 * builtin -- OpenSSL の内蔵キャッシュが 1 つのワーカプロセスに対してのみ用いられます. The cache size is assigned in the number of the sessions. Note: there appears to be a memory fragmentation issue using this method, please take that into consideration when using this. See "References" below.
 * shared -- キャッシュがすべてのワーカプロセス間で共有されます. キャッシュのサイズはバイト単位で指定します. 1 MB のキャッシュで約 4,000 セッションを格納できます. Each shared cache must be given an arbitrary name. A shared cache with a given name can be used in several virtual hosts.

ssl_session_cache builtin:1000  shared:SSL:10m; Bear in mind however, that using only shared cache, i.e., without builtin, should be more effective.

Nginx バージョン 0.8.34 以前において、このディレクティブは ssl_verify_client が 'on' もしくは 'optional' の場合、'none' や 'off' にすべきではありません.

listen [::]:443 ssl default_server; This is so because session resumption happens before any TLS extensions are enabled, namely Server Name Identification (SNI). The ClientHello message requests a session ID from a given IP address (server). For that to work the default server setting is required.
 * Note that for session resumption to work you'll need to have, at least, the server configured as default for the SSL socket. Like this:

A preferred approach is to move the  directive to the   context. The (minor) downside is that all configured virtual hosts get the same SSL cache settings.

ssl_session_timeout


このディレクティブは、クライアントが SSL キャッシュに格納されているセキュアセッションのネゴシエーション済の暗号パラメータを再利用することができる最大期間を指定します.

ssl_engine
syntax: ssl_engine

This allows specifying the OpenSSL engine to use, like PadLock, for example. It requires a recent version of OpenSSL. To verify if the OpenSSL version installed in your platform supports this, issue the command: openssl engine On a Debian testing with OpenSSL version 0.9.8o from 01 Jun 2010 it returns: $ openssl engine (padlock) VIA PadLock (no-RNG, no-ACE) (dynamic) Dynamic engine loading support

= ビルトイン変数 = ngx_http_ssl モジュールは、以下のビルトイン変数をサポートします:


 * $ssl_cipher returns the cipher suite being used for the currently established SSL/TLS connection
 * $ssl_client_serial returns the serial number of the client certificate for the currently established SSL/TLS connection &mdash; if applicable, i.e., if client authentication is activated in the connection
 * $ssl_client_s_dn クライアント認証がコネクションで有効になっている場合など、可能な場合について、現在 SSL/TLS コネクションを確立しているクライアント証明書の subject のDistinguished Name (DN) を返却する.
 * $ssl_client_i_dn returns the issuer DN of the client certificate for the currently established SSL/TLS connection &mdash; if applicable, i.e., if client authentication is activated in the connection
 * $ssl_protocol returns the protocol of the currently established SSL/TLS connection &mdash; depending on the configuration and client available options it's one of SSLv2, SSLv3 or TLSv1
 * $ssl_session_id the Session ID of the established secure connection &mdash; requires Nginx version greater or equal to 0.8.20
 * $ssl_client_cert
 * $ssl_client_raw_cert
 * $ssl_client_verify クライアント証明の確認が成功した場合は、値 "SUCCESS" をとる

= 非標準のエラーコード =

このモジュールでは、 ディレクティブと併用することでデバッグを容易にするため、非標準のエラーコードをいくつかサポートしています.

Debugging is done after the request is completely "disassembled" and it's components are accessible via variables such as $request_uri, $uri, $arg and more.
 * 495 - クライアント証明書のチェックがエラーとなった
 * 496 - クライアントが必要な証明書を提示しなかった
 * 497 - 通常のリクエストが HTTPS に送られた

= References =
 * Original Documentation
 * Implementing an actual SSL Certificate
 * SSL Memory Fragmentation and new default status for ssl_session_cache