Configuring HTTPS servers | ![]() english עברית 日本語 русский türkçe news about download security advisories documentation introduction pgp keys howto faq trac wiki links books support donation nginx.com | |
To configure an HTTPS server you must enable the SSL protocol in the server block, and specify the locations of the server certificate and private key files: The server certificate is a public entity. It is sent to every client that connects to the server. The private key is a secure entity and should be stored in a file with restricted access, however, it must be readable by nginx’s master process. The private key may alternately be stored in the same file as the certificate: in which case the file access rights should also be restricted. Although the certificate and the key are stored in one file, only the certificate is sent to a client.
The directives ssl_protocols and
ssl_ciphers
can be used to limit connections
to include only the strong versions and ciphers of SSL/TLS.
Since version 1.0.5, nginx uses “ CBC-mode ciphers might be vulnerable to a number of attacks and to the BEAST attack in particular (see CVE-2011-3389). Configuration of ciphers can be adjusted to prefer RC4-SHA as the following:
HTTPS server optimizationSSL operations consume extra CPU resources. On multi-processor systems you should run several worker processes: no less than the number of available CPU cores. The most CPU-intensive operation is the SSL handshake. There are two ways to minimize the number of these operations per client: the first is by enabling keepalive connections to send several requests via one connection and the second is to reuse SSL session parameters to avoid SSL handshakes for parallel and subsequent connections. The sessions are stored in an SSL session cache shared between workers and configured by the ssl_session_cache directive. One megabyte of the cache contains about 4000 sessions. The default cache timeout is 5 minutes. It can be increased by using the ssl_session_timeout directive. Here is a sample configuration optimized for a quad core system with 10M shared session cache:
SSL certificate chainsSome browsers may complain about a certificate signed by a well-known certificate authority, while other browsers may accept the certificate without issues. This occurs because the issuing authority has signed the server certificate using an intermediate certificate that is not present in the certificate base of well-known trusted certificate authorities which is distributed with a particular browser. In this case the authority provides a bundle of chained certificates which should be concatenated to the signed server certificate. The server certificate must appear before the chained certificates in the combined file: $ cat www.nginx.com.crt bundle.crt > www.nginx.com.chained.crt The resulting file should be used in the ssl_certificate directive: If the server certificate and the bundle have been concatenated in the wrong order, nginx will fail to start and will display the error message: because nginx has tried to use the private key with the bundle’s first certificate instead of the server certificate.
Browsers usually store intermediate certificates which they receive
and which are signed by trusted authorities, so actively used browsers
may already have the required intermediate certificates and
may not complain about a certificate sent without a chained bundle.
To ensure the server sends the complete certificate chain,
you may use the In this example the subject (“s”) of the www.GoDaddy.com server certificate #0 is signed by an issuer (“i”) which itself is the subject of the certificate #1, which is signed by an issuer which itself is the subject of the certificate #2, which signed by the well-known issuer ValiCert, Inc. whose certificate is stored in the browsers’ built-in certificate base (that lay in the house that Jack built). If you have not added the certificates bundle, you will see only your server certificate #0. A single HTTP/HTTPS server
It is good practice to configure separate servers for HTTP and HTTPS
protocols from the very start. Although their functionalities currently
seem equal, this may change significantly in the future
and using a consolidated server may become problematic.
However, if HTTP and HTTPS servers are equal,
and you prefer not to think about the future,
you may configure a single server that handles both HTTP and HTTPS requests
by deleting the directive “
Prior to 0.8.21, nginx only allows the
Name-based HTTPS serversA common issue arises when configuring two or more HTTPS servers listening on a single IP address: With this configuration a browser receives the certificate of the default server, i.e., www.nginx.com regardless of the requested server name. This is caused by SSL protocol behaviour. The SSL connection is established before the browser sends an HTTP request and nginx does not know the name of the requested server. Therefore, it may only offer the certificate of the default server. The oldest and most robust method to resolve the issue is to assign a separate IP address for every HTTPS server:
A SSL certificate with several namesThere are other ways to share a single IP address between several HTTPS servers, however, all of them have drawbacks. One way is to use a certificate with several names in the SubjectAltName certificate field, for example, www.nginx.com and www.nginx.org. However, the SubjectAltName field length is limited. Another way is to use a certificate with a wildcard name, for example, *.nginx.org. This certificate matches www.nginx.org, but does not match nginx.org and www.sub.nginx.org. These two methods can also be combined. A certificate may contain exact and wildcard names in the SubjectAltName field, for example, nginx.org and *.nginx.org. It is better to place a certificate file with several names and its private key file at the http level of configuration to inherit their single memory copy in all servers:
Server Name IndicationA more generic solution for running several HTTPS servers on a single IP address is TLSv1.1 Server Name Indication extension (SNI, RFC3546), which allows a browser to pass a requested server name during the SSL handshake and, therefore, the server will know which certificate it should use for the connection. However, SNI has limited browser support. Currently it is supported starting with the following browsers versions:
In order to use SNI in nginx, it must be supported in both the
OpenSSL library with which the nginx binary has been built as well as
the library to which it is being dynamically linked at run time.
OpenSSL supports SNI since 0.9.8f version if it was built with config option
$ nginx -V ... TLS SNI support enabled ... However, if the SNI-enabled nginx is linked dynamically to an OpenSSL library without SNI support, nginx displays the warning: nginx was built with SNI support, however, now it is linked dynamically to an OpenSSL library which has no tlsext support, therefore SNI is not available
Compatibility
|