The ngx_http_ssl_module
module provides the necessary support for HTTPS.
This module is not built by default, it should be enabled with the --with-http_ssl_module
configuration parameter.
This module requires the OpenSSL library.
To reduce the processor load it is recommended to
worker_processes auto; http { ... server { listen 443 ssl; keepalive_timeout 70; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 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; ... }
Syntax: | ssl |
---|---|
Default: | ssl off; |
Context: | http , server |
Enables the HTTPS protocol for the given virtual server.
It is recommended to use the ssl
parameter of the listen directive instead of this directive.
Syntax: | ssl_buffer_size |
---|---|
Default: | ssl_buffer_size 16k; |
Context: | http , server |
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;
Syntax: | ssl_certificate |
---|---|
Default: | — |
Context: | http , server |
Specifies a file
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; ... }
Only OpenSSL 1.0.2 or higher supports separate certificate chains for different certificates. With older versions, only one certificate chain can be used.
It should be kept in mind that due to the HTTPS protocol limitations virtual servers should listen on different IP addresses:
server { listen 192.168.1.1:443; server_name one.example.com; ssl_certificate one.example.com.crt; ... } server { listen 192.168.1.2:443; server_name two.example.com; ssl_certificate two.example.com.crt; ... }
otherwise the first server’s certificate will be issued for the second site.
Syntax: | ssl_certificate_key |
---|---|
Default: | — |
Context: | http , server |
Specifies a file
with the secret key in the PEM format for the given virtual server.
The value engine
:name
:id
can be specified instead of the file
(1.7.9), which loads a secret key with a specified id
from the OpenSSL engine name
.
Syntax: | ssl_ciphers |
---|---|
Default: | ssl_ciphers HIGH:!aNULL:!MD5; |
Context: | http , server |
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 “openssl ciphers
” command.
The previous versions of nginx used different ciphers by default.
Syntax: | ssl_client_certificate |
---|---|
Default: | — |
Context: | http , server |
Specifies a file
with trusted CA certificates in the PEM format used to verify client certificates and OCSP responses if ssl_stapling is enabled.
The list of certificates will be sent to clients. If this is not desired, the ssl_trusted_certificate directive can be used.
Syntax: | ssl_crl |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 0.8.7.
Specifies a file
with revoked certificates (CRL) in the PEM format used to verify client certificates.
Syntax: | ssl_dhparam |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 0.7.2.
Specifies a file
with DH parameters for DHE ciphers.
Syntax: | ssl_ecdh_curve |
---|---|
Default: | ssl_ecdh_curve auto; |
Context: | http , server |
This directive appeared in versions 1.1.0 and 1.0.6.
Specifies a curve
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 auto
(1.11.0) instructs nginx to use a list built into the OpenSSL library when using OpenSSL 1.0.2 or higher, or prime256v1
with older versions.
Prior to version 1.11.0, the prime256v1
curve was used by default.
Syntax: | ssl_password_file |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 1.7.3.
Specifies a file
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; } }
Syntax: | ssl_prefer_server_ciphers |
---|---|
Default: | ssl_prefer_server_ciphers off; |
Context: | http , server |
Specifies that server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols.
Syntax: | ssl_protocols
[ |
---|---|
Default: | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
Context: | http , server |
Enables the specified protocols. The TLSv1.1
and TLSv1.2
parameters work only when the OpenSSL library of version 1.0.1 or higher is used.
TheTLSv1.1
andTLSv1.2
parameters are supported starting from versions 1.1.13 and 1.0.12, so when the OpenSSL version 1.0.1 or higher is used on older nginx versions, these protocols work, but cannot be disabled.
Syntax: | ssl_session_cache
|
---|---|
Default: | ssl_session_cache none; |
Context: | http , server |
Sets the types and sizes of caches that store session parameters. A cache can be of any of the following types:
off
none
builtin
shared
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.
Syntax: | ssl_session_ticket_key |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 1.5.7.
Sets a file
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 file
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.
Syntax: | ssl_session_tickets |
---|---|
Default: | ssl_session_tickets on; |
Context: | http , server |
This directive appeared in version 1.5.9.
Enables or disables session resumption through TLS session tickets.
Syntax: | ssl_session_timeout |
---|---|
Default: | ssl_session_timeout 5m; |
Context: | http , server |
Specifies a time during which a client may reuse the session parameters.
Syntax: | ssl_stapling |
---|---|
Default: | ssl_stapling off; |
Context: | http , server |
This directive appeared in version 1.3.7.
Enables or disables stapling of OCSP responses 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 ssl_certificate file does not contain intermediate certificates, the certificate of the server certificate issuer should be present in the ssl_trusted_certificate file.
For a resolution of the OCSP responder hostname, the resolver directive should also be specified.
Syntax: | ssl_stapling_file |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 1.3.7.
When set, the stapled OCSP response will be taken from the specified file
instead of querying the OCSP responder specified in the server certificate.
The file should be in the DER format as produced by the “openssl ocsp
” command.
Syntax: | ssl_stapling_responder |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 1.3.7.
Overrides the URL of the OCSP responder specified in the “Authority Information Access” certificate extension.
Only “http://
” OCSP responders are supported:
ssl_stapling_responder http://ocsp.example.com/;
Syntax: | ssl_stapling_verify |
---|---|
Default: | ssl_stapling_verify off; |
Context: | http , server |
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 ssl_trusted_certificate directive.
Syntax: | ssl_trusted_certificate |
---|---|
Default: | — |
Context: | http , server |
This directive appeared in version 1.3.7.
Specifies a file
with trusted CA certificates in the PEM format used to verify client certificates and OCSP responses if ssl_stapling is enabled.
In contrast to the certificate set by ssl_client_certificate, the list of these certificates will not be sent to clients.
Syntax: | ssl_verify_client
|
---|---|
Default: | ssl_verify_client off; |
Context: | http , server |
Enables verification of client certificates. The verification result is stored in the $ssl_client_verify variable.
The optional
parameter (0.8.7+) requests the client certificate and verifies it if the certificate is present.
The optional_no_ca
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.
Syntax: | ssl_verify_depth |
---|---|
Default: | ssl_verify_depth 1; |
Context: | http , server |
Sets the verification depth in the client certificates chain.
The ngx_http_ssl_module
module supports several non-standard error codes that can be used for redirects using the error_page directive:
The redirection happens after the request is fully parsed and the variables, such as $request_uri
, $uri
, $args
and others, are available.
The ngx_http_ssl_module
module supports several embedded variables:
$ssl_cipher
$ssl_ciphers
AES128-SHA:AES256-SHA:0x00ff
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.
$ssl_client_cert
$ssl_client_fingerprint
$ssl_client_i_dn
$ssl_client_i_dn_legacy
Prior to version 1.11.6, the variable name was $ssl_client_i_dn
.
$ssl_client_raw_cert
$ssl_client_s_dn
$ssl_client_s_dn_legacy
Prior to version 1.11.6, the variable name was $ssl_client_s_dn
.
$ssl_client_serial
$ssl_client_v_end
$ssl_client_v_remain
$ssl_client_v_start
$ssl_client_verify
SUCCESS
”, “FAILED:
reason
”, and “NONE
” if a certificate was not present; Prior to version 1.11.7, the “FAILED
” result did not contain thereason
string.
$ssl_curves
0x001d:prime256v1:secp521r1:secp384r1
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.
The variable is available only for new sessions.
$ssl_protocol
$ssl_server_name
$ssl_session_id
$ssl_session_reused
r
” if an SSL session was reused, or “.
” otherwise (1.5.11).
© 2002-2017 Igor Sysoev
© 2011-2017 Nginx, Inc.
Licensed under the BSD License.
https://nginx.org/en/docs/http/ngx_http_ssl_module.html