=encoding utf-8 =head1 NAME ngx_http_ssl_module - Module ngx_http_ssl_module =head1 The C module provides the necessary support for HTTPS. This module is not built by default, it should be enabled with the C<--with-http_ssl_module> configuration parameter. B This module requires the L library. =head1 Example Configuration To reduce the processor load it is recommended to =over =item * set the number of L equal to the number of processors, =item * enable L connections, =item * enable the shared session cache, =item * disable the built-in session cache, =item * and possibly increase the session lifetime (by default, 5 minutes): =back worker_processes auto; http { ... server { listen 443 ssl; keepalive_timeout 70; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5; ssl_certificate /usr/local/nginx/conf/cert.pem; ssl_certificate_key /usr/local/nginx/conf/cert.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ... } =head1 Directives =head2 ssl B ssl I E C> B I B I B I This directive was made obsolete in version 1.15.0 and was removed in version 1.25.1. The C parameter of the L directive should be used instead. =head2 ssl_buffer_size B ssl_buffer_size I>> B I<16k> B I B I This directive appeared in version 1.5.9. Sets the size of the buffer used for sending data. By default, the buffer size is 16k, which corresponds to minimal overhead when sending big responses. To minimize Time To First Byte it may be beneficial to use smaller values, for example: ssl_buffer_size 4k; =head2 ssl_certificate B ssl_certificate I>> B I B I Specifies a I> with the certificate in the PEM format for the given virtual server. If intermediate certificates should be specified in addition to a primary certificate, they should be specified in the same file in the following order: the primary certificate comes first, then the intermediate certificates. A secret key in the PEM format may be placed in the same file. Since version 1.11.0, this directive can be specified multiple times to load certificates of different types, for example, RSA and ECDSA: server { listen 443 ssl; server_name example.com; ssl_certificate example.com.rsa.crt; ssl_certificate_key example.com.rsa.key; ssl_certificate example.com.ecdsa.crt; ssl_certificate_key example.com.ecdsa.key; ... } B Only OpenSSL 1.0.2 or higher supports separate L for different certificates. With older versions, only one certificate chain can be used. Since version 1.15.9, variables can be used in the I> name when using OpenSSL 1.0.2 or higher: ssl_certificate $ssl_server_name.crt; ssl_certificate_key $ssl_server_name.key; Note that using variables implies that a certificate will be loaded for each SSL handshake, and this may have a negative impact on performance. The value C:I> can be specified instead of the I> (1.15.10), which loads a certificate from a variable without using intermediate files. Note that inappropriate use of this syntax may have its security implications, such as writing secret key data to L. It should be kept in mind that due to the HTTPS protocol limitations for maximum interoperability virtual servers should listen on L. =head2 ssl_certificate_cache B ssl_certificate_cache I> B ssl_certificate_cache I< C=I> [C=I>] [C=I>]> B I B I B I This directive appeared in version 1.27.4. Defines a cache that stores SSL certificates and secret keys specified with variables. The directive has the following parameters: =over =item C sets the maximum number of elements in the cache; on cache overflow the least recently used (LRU) elements are removed; =item C defines a time after which an element is removed from the cache if it has not been accessed during this time; by default, it is 10 seconds; =item C defines a time during which an element in the cache is considered valid and can be reused; by default, it is 60 seconds. Certificates that exceed this time will be reloaded or revalidated; =item C disables the cache. =back Example: ssl_certificate $ssl_server_name.crt; ssl_certificate_key $ssl_server_name.key; ssl_certificate_cache max=1000 inactive=20s valid=1m; =head2 ssl_certificate_key B ssl_certificate_key I>> B I B I Specifies a I> with the secret key in the PEM format for the given virtual server. The value C:I>:I> can be specified instead of the I> (1.7.9), which loads a secret key with a specified I> from the OpenSSL engine I>. The value C:I> can be specified instead of the I> (1.15.10), which loads a secret key from a variable without using intermediate files. Note that inappropriate use of this syntax may have its security implications, such as writing secret key data to L. Since version 1.15.9, variables can be used in the I> name when using OpenSSL 1.0.2 or higher. =head2 ssl_ciphers B ssl_ciphers I>> B I B I B I Specifies the enabled ciphers. The ciphers are specified in the format understood by the OpenSSL library, for example: ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; The full list can be viewed using the “C” command. B The previous versions of nginx used L ciphers by default. =head2 ssl_client_certificate B ssl_client_certificate I>> B I B I Specifies a I> with trusted CA certificates in the PEM format used to verify client certificates and OCSP responses if L is enabled. The list of certificates will be sent to clients. If this is not desired, the L directive can be used. =head2 ssl_conf_command B ssl_conf_command I> I>> B I B I This directive appeared in version 1.19.4. Sets arbitrary OpenSSL configuration L. B The directive is supported when using OpenSSL 1.0.2 or higher. Several C directives can be specified on the same level: ssl_conf_command Options PrioritizeChaCha; ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256; These directives are inherited from the previous configuration level if and only if there are no C directives defined on the current level. B Note that configuring OpenSSL directly might result in unexpected behavior. =head2 ssl_crl B ssl_crl I>> B I B I This directive appeared in version 0.8.7. Specifies a I> with revoked certificates (CRL) in the PEM format used to verify client certificates. =head2 ssl_dhparam B ssl_dhparam I>> B I B I This directive appeared in version 0.7.2. Specifies a I> with DH parameters for DHE ciphers. By default no parameters are set, and therefore DHE ciphers will not be used. B Prior to version 1.11.0, builtin parameters were used by default. =head2 ssl_early_data B ssl_early_data I E C> B I B I B I This directive appeared in version 1.15.3. Enables or disables TLS 1.3 L. B Requests sent within early data are subject to L. To protect against such attacks at the application layer, the $ssl_early_data variable should be used. proxy_set_header Early-Data $ssl_early_data; B The directive is supported when using OpenSSL 1.1.1 or higher (1.15.4) and L. =head2 ssl_ecdh_curve B ssl_ecdh_curve I>> B I B I B I This directive appeared in version 1.1.0. This directive appeared in version 1.0.6. Specifies a I> for ECDHE ciphers. When using OpenSSL 1.0.2 or higher, it is possible to specify multiple curves (1.11.0), for example: ssl_ecdh_curve prime256v1:secp384r1; The special value C (1.11.0) instructs nginx to use a list built into the OpenSSL library when using OpenSSL 1.0.2 or higher, or C with older versions. B Prior to version 1.11.0, the C curve was used by default. B When using OpenSSL 1.0.2 or higher, this directive sets the list of curves supported by the server. Thus, in order for ECDSA certificates to work, it is important to include the curves used in the certificates. =head2 ssl_key_log B ssl_key_log I B I B I This directive appeared in version 1.27.2. Enables logging of client connection SSL keys and specifies the path to the key log file. Keys are logged in the L format compatible with Wireshark. B This directive is available as part of our commercial subscription. =head2 ssl_ocsp B ssl_ocsp I E C E C> B I B I B I This directive appeared in version 1.19.0. Enables OCSP validation of the client certificate chain. The C parameter enables validation of the client certificate only. For the OCSP validation to work, the L directive should be set to C or C. To resolve the OCSP responder hostname, the L directive should also be specified. Example: ssl_verify_client on; ssl_ocsp on; resolver 192.0.2.1; =head2 ssl_ocsp_cache B ssl_ocsp_cache I< C E [C:I>:I>]> B I B I B I This directive appeared in version 1.19.0. Sets C and C of the cache that stores client certificates status for OCSP validation. The cache is shared between all worker processes. A cache with the same name can be used in several virtual servers. The C parameter prohibits the use of the cache. =head2 ssl_ocsp_responder B ssl_ocsp_responder I>> B I B I This directive appeared in version 1.19.0. Overrides the URL of the OCSP responder specified in the “L” certificate extension for validation of client certificates. Only “CE>” OCSP responders are supported: ssl_ocsp_responder http://ocsp.example.com/; =head2 ssl_password_file B ssl_password_file I>> B I B I This directive appeared in version 1.7.3. Specifies a I> with passphrases for secret keys where each passphrase is specified on a separate line. Passphrases are tried in turn when loading the key. Example: http { ssl_password_file /etc/keys/global.pass; ... server { server_name www1.example.com; ssl_certificate_key /etc/keys/first.key; } server { server_name www2.example.com; # named pipe can also be used instead of a file ssl_password_file /etc/keys/fifo; ssl_certificate_key /etc/keys/second.key; } } =head2 ssl_prefer_server_ciphers B ssl_prefer_server_ciphers I E C> B I B I B I Specifies that server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols. =head2 ssl_protocols B ssl_protocols I< [C] [C] [C] [C] [C] [C]> B I B I B I Enables the specified protocols. If the directive is specified on the L level, the value from the default server can be used. Details are provided in the “L” section. B The C and C parameters (1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used. B The C parameter (1.13.0) works only when OpenSSL 1.1.1 or higher is used. B The C parameter is used by default since 1.23.4. =head2 ssl_reject_handshake B ssl_reject_handshake I E C> B I B I B I This directive appeared in version 1.19.4. If enabled, SSL handshakes in the L block will be rejected. For example, in the following configuration, SSL handshakes with server names other than C are rejected: server { listen 443 ssl default_server; ssl_reject_handshake on; } server { listen 443 ssl; server_name example.com; ssl_certificate example.com.crt; ssl_certificate_key example.com.key; } =head2 ssl_session_cache B ssl_session_cache I< C E C E [C[:I>]] [C:I>:I>]> B I B I B I Sets the types and sizes of caches that store session parameters. A cache can be of any of the following types: =over =item C the use of a session cache is strictly prohibited: nginx explicitly tells a client that sessions may not be reused. =item C the use of a session cache is gently disallowed: nginx tells a client that sessions may be reused, but does not actually store session parameters in the cache. =item C a cache built in OpenSSL; used by one worker process only. The cache size is specified in sessions. If size is not given, it is equal to 20480 sessions. Use of the built-in cache can cause memory fragmentation. =item C a cache shared between all worker processes. The cache size is specified in bytes; one megabyte can store about 4000 sessions. Each shared cache should have an arbitrary name. A cache with the same name can be used in several virtual servers. It is also used to automatically generate, store, and periodically rotate TLS session ticket keys (1.23.2) unless configured explicitly using the L directive. =back Both cache types can be used simultaneously, for example: ssl_session_cache builtin:1000 shared:SSL:10m; but using only shared cache without the built-in cache should be more efficient. =head2 ssl_session_ticket_key B ssl_session_ticket_key I>> B I B I This directive appeared in version 1.5.7. Sets a I> with the secret key used to encrypt and decrypt TLS session tickets. The directive is necessary if the same key has to be shared between multiple servers. By default, a randomly generated key is used. If several keys are specified, only the first key is used to encrypt TLS session tickets. This allows configuring key rotation, for example: ssl_session_ticket_key current.key; ssl_session_ticket_key previous.key; The I> must contain 80 or 48 bytes of random data and can be created using the following command: openssl rand 80 > ticket.key Depending on the file size either AES256 (for 80-byte keys, 1.11.8) or AES128 (for 48-byte keys) is used for encryption. =head2 ssl_session_tickets B ssl_session_tickets I E C> B I B I B I This directive appeared in version 1.5.9. Enables or disables session resumption through L. =head2 ssl_session_timeout B ssl_session_timeout I>> B I<5m> B I B I Specifies a time during which a client may reuse the session parameters. =head2 ssl_stapling B ssl_stapling I E C> B I B I B I This directive appeared in version 1.3.7. Enables or disables L by the server. Example: ssl_stapling on; resolver 192.0.2.1; For the OCSP stapling to work, the certificate of the server certificate issuer should be known. If the L file does not contain intermediate certificates, the certificate of the server certificate issuer should be present in the L file. For a resolution of the OCSP responder hostname, the L directive should also be specified. =head2 ssl_stapling_file B ssl_stapling_file I>> B I B I This directive appeared in version 1.3.7. When set, the stapled OCSP response will be taken from the specified I> instead of querying the OCSP responder specified in the server certificate. The file should be in the DER format as produced by the “C” command. =head2 ssl_stapling_responder B ssl_stapling_responder I>> B I B I This directive appeared in version 1.3.7. Overrides the URL of the OCSP responder specified in the “L” certificate extension. Only “CE>” OCSP responders are supported: ssl_stapling_responder http://ocsp.example.com/; =head2 ssl_stapling_verify B ssl_stapling_verify I E C> B I B I B I This directive appeared in version 1.3.7. Enables or disables verification of OCSP responses by the server. For verification to work, the certificate of the server certificate issuer, the root certificate, and all intermediate certificates should be configured as trusted using the L directive. =head2 ssl_trusted_certificate B ssl_trusted_certificate I>> B I B I This directive appeared in version 1.3.7. Specifies a I> with trusted CA certificates in the PEM format used to verify client certificates and OCSP responses if L is enabled. In contrast to the certificate set by L, the list of these certificates will not be sent to clients. =head2 ssl_verify_client B ssl_verify_client I< C E C E C E C> B I B I B I Enables verification of client certificates. The verification result is stored in the $ssl_client_verify variable. The C parameter (0.8.7+) requests the client certificate and verifies it if the certificate is present. The C parameter (1.3.8, 1.2.5) requests the client certificate but does not require it to be signed by a trusted CA certificate. This is intended for the use in cases when a service that is external to nginx performs the actual certificate verification. The contents of the certificate is accessible through the $ssl_client_cert variable. =head2 ssl_verify_depth B ssl_verify_depth I>> B I<1> B I B I Sets the verification depth in the client certificates chain. =head1 Error Processing The C module supports several non-standard error codes that can be used for redirects using the L directive: =over =item C<495> an error has occurred during the client certificate verification; =item C<496> a client has not presented the required certificate; =item C<497> a regular request has been sent to the HTTPS port. =back The redirection happens after the request is fully parsed and the variables, such as C<$request_uri>, C<$uri>, C<$args> and others, are available. =head1 Embedded Variables The C module supports embedded variables: =over =item C<$ssl_alpn_protocol> returns the protocol selected by ALPN during the SSL handshake, or an empty string otherwise (1.21.4); =item C<$ssl_cipher> returns the name of the cipher used for an established SSL connection; =item C<$ssl_ciphers> returns the list of ciphers supported by the client (1.11.7). Known ciphers are listed by names, unknown are shown in hexadecimal, for example: AES128-SHA:AES256-SHA:0x00ff B The variable is fully supported only when using OpenSSL version 1.0.2 or higher. With older versions, the variable is available only for new sessions and lists only known ciphers. =item C<$ssl_client_escaped_cert> returns the client certificate in the PEM format (urlencoded) for an established SSL connection (1.13.5); =item C<$ssl_client_cert> returns the client certificate in the PEM format for an established SSL connection, with each line except the first prepended with the tab character; this is intended for the use in the L directive; B The variable is deprecated, the C<$ssl_client_escaped_cert> variable should be used instead. =item C<$ssl_client_fingerprint> returns the SHA1 fingerprint of the client certificate for an established SSL connection (1.7.1); =item C<$ssl_client_i_dn> returns the “issuer DN” string of the client certificate for an established SSL connection according to L (1.11.6); =item C<$ssl_client_i_dn_legacy> returns the “issuer DN” string of the client certificate for an established SSL connection; B Prior to version 1.11.6, the variable name was C<$ssl_client_i_dn>. =item C<$ssl_client_raw_cert> returns the client certificate in the PEM format for an established SSL connection; =item C<$ssl_client_s_dn> returns the “subject DN” string of the client certificate for an established SSL connection according to L (1.11.6); =item C<$ssl_client_s_dn_legacy> returns the “subject DN” string of the client certificate for an established SSL connection; B Prior to version 1.11.6, the variable name was C<$ssl_client_s_dn>. =item C<$ssl_client_serial> returns the serial number of the client certificate for an established SSL connection; =item C<$ssl_client_v_end> returns the end date of the client certificate (1.11.7); =item C<$ssl_client_v_remain> returns the number of days until the client certificate expires (1.11.7); =item C<$ssl_client_v_start> returns the start date of the client certificate (1.11.7); =item C<$ssl_client_verify> returns the result of client certificate verification: “C”, “CI>”, and “C” if a certificate was not present; B Prior to version 1.11.7, the “C” result did not contain the I> string. =item C<$ssl_curve> returns the negotiated curve used for SSL handshake key exchange process (1.21.5). Known curves are listed by names, unknown are shown in hexadecimal, for example: prime256v1 B The variable is supported only when using OpenSSL version 3.0 or higher. With older versions, the variable value will be an empty string. =item C<$ssl_curves> returns the list of curves supported by the client (1.11.7). Known curves are listed by names, unknown are shown in hexadecimal, for example: 0x001d:prime256v1:secp521r1:secp384r1 B The variable is supported only when using OpenSSL version 1.0.2 or higher. With older versions, the variable value will be an empty string. B The variable is available only for new sessions. =item C<$ssl_early_data> returns “C<1>” if TLS 1.3 early data is used and the handshake is not complete, otherwise “” (1.15.3). =item C<$ssl_protocol> returns the protocol of an established SSL connection; =item C<$ssl_server_name> returns the server name requested through L (1.7.0); =item C<$ssl_session_id> returns the session identifier of an established SSL connection; =item C<$ssl_session_reused> returns “C” if an SSL session was reused, or “C<.>” otherwise (1.5.11). =back