MC-BARS.COMDomains · SSL · HTTPS · Guides

Home / Articles / Nginx and SSL

SSL for Nginx: certificate installation, TLS 1.3, HTTPS, and security

Home / Articles / SSL on Nginx
Practical guide · NGINX / SSL / TLS

SSL for Nginx: certificate installation, TLS 1.3, HTTPS, and security

Step-by-step HTTPS setup on Nginx: how to issue a Let’s Encrypt certificate, enable TLS 1.3, configure redirects, verify the chain of trust, and set up automatic renewal.

Updated: November 5, 2026 · System administration · Reading time: 25–35 minutes

Before you begin: all commands are shown using a test domain example.ru. For a production server, you need a backup and must check the configuration before applying it. Do not share passwords or private keys with third-party services.

1. What installing SSL on Nginx means and what you need to achieve

HTTPS on Nginx: server, certificate, and secure connection
HTTPS on Nginx: server, certificate, and secure connection. Original thematic illustration; interfaces are illustrative.

The Nginx web server can accept requests over regular HTTP and secure HTTPS. For the latter to work, the server needs a certificate that matches the domain name, the corresponding private key, and correct TLS parameters. In modern guides, the words “install SSL” mean configuring TLS: old SSL versions should no longer be enabled.

A certificate confirms that a public key is associated with a specific domain name. The browser checks the expiration date, chain of trust, and SAN name list. The browser and server then establish a secure connection through which regular HTTP requests and responses are transmitted. It is not enough to specify the correct file path: DNS must point to the right server, the virtual host must serve the domain, and the web server must provide the complete chain.

A successful setup has five practical outcomes: the domain opens over HTTPS without warnings; the HTTP address redirects to the chosen HTTPS version; the certificate covers all addresses in use; automatic renewal works; and Nginx reloads the updated files after renewal. The commands shown are intended for a Linux server that you administer yourself. On shared hosting without root access, the process is usually managed through the provider’s control panel.

2. Prerequisites: domain, DNS, ports, and server access

Before issuing a certificate, check more than just whether Nginx is installed. The domain must have valid A records and, if IPv6 is used, AAAA. If a domain has several IP addresses, each address may point to a different server and return a different certificate. So after moving a site, checking one IPv4 address does not prove that everything works for visitors over IPv6.

For standard HTTP-01 domain validation, the certificate authority must be able to reach the site from outside over port 80. Users need port 443 for HTTPS. A firewall, cloud provider rules, NAT, and external load balancers can block the connection even when Nginx itself is configured correctly.

dig +short A example.ru
dig +short AAAA example.ru
curl -I http://example.ru
sudo nginx -v
sudo nginx -t
sudo ss -ltnp | grep -E ":(80|443)\b"

Replace example.ru in the commands with the real domain. A response from curl is useful for an initial check, but a local server may connect to itself differently from an external visitor. For a production launch, also verify the result from an independent network.

You also need access to configuration backups, error logs, and a way to roll back changes. If the server hosts multiple sites, changes to shared files nginx.conf must be coordinated: an error in one block can prevent the entire service from reloading its configuration.

3. How Nginx configuration works and where its files are located

On Debian and Ubuntu, the directories /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/are commonly used. Other builds and containers may use /etc/nginx/conf.d/, with the main configuration file named /etc/nginx/nginx.conf. Do not assume a single path works everywhere: find the location with the commands nginx -V and nginx -T, using administrator privileges as needed.

The directive server_name specifies which names the virtual server should serve. The directive listen 443 ssl; enables HTTPS on the relevant port. ssl_certificate sets the certificate file, while ssl_certificate_key sets the private key. In a typical Certbot installation, the file fullchain.pem contains the site certificate along with the required intermediate certificates.

sudo nginx -T | grep -E "server_name|listen|ssl_certificate"
sudo cp -a /etc/nginx /etc/nginx.backup-before-ssl

A configuration snapshot is needed before making any automatic changes. When restoring it, account for file owners, symbolic links, and the installed Nginx version. Simply copying a configuration line into the wrong context can cause an error that will be detected by nginx -t.

4. A minimal HTTP site before issuing a certificate

At the first stage, it is easiest to make sure the site works over regular HTTP. If Nginx serves static pages, rootis commonly used; if the site runs on a Node.js application, PHP-FPM, or another server, the corresponding configuration proxy_pass or fastcgi_pass.

server {
    listen 80;
    listen [::]:80;
    server_name example.ru www.example.ru;

    root /var/www/example.ru/public;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

This is an example for a static site and a real file directory. The path /var/www/example.ru/public must exist, and the Nginx process must have read access. For WordPress, you cannot use this example without configuring PHP-FPM: otherwise, PHP files may not execute. For an application served through a proxy, root you will need a reverse-proxy configuration, not an address inserted into an arbitrary location.

Enable the virtual server file using the method provided by the system. Then check the configuration and reload Nginx: sudo nginx -t, then sudo systemctl reload nginx. If the check fails, do not reload until the error is fixed. After a successful check, open http://example.ru and make sure the correct site loads.

5. Installing Certbot: choosing a method and checking compatibility

Automated certificate issuance with Certbot and Nginx
Automated certificate issuance with Certbot and Nginx. Original thematic illustration; interfaces are illustrative.

Certbot is an ACME client that helps request a certificate from a certificate authority, prove control of a domain, and configure subsequent renewal. A dedicated plugin is available for Nginx and can modify the virtual host configuration automatically. Use instructions for your specific system, since package installation recommendations differ for Ubuntu, Debian, other Linux distributions, and container environments.

The official Certbot guide recommends installing through Snap for a number of Linux systems. In some environments, Certbot is already provided by the package manager or by the hosting provider. Avoid mixing incompatible Certbot installations from Snap, apt, and pip: this makes it harder to identify the executable, locate certificates, and determine the renewal schedule.

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
certbot --version

These commands work only on systems where Snap is installed and running. Before creating the link, make sure /usr/local/bin/certbot does not already exist or point to another program. On Debian-based systems, distribution packages certbot and python3-certbot-nginxmay be an alternative; check their versions and lifecycle in the repository. With managed hosting, you usually do not need to install Certbot manually.

6. Quickly issue a Let’s Encrypt certificate with the certbot --nginx command

After checking DNS and backing up the configuration, you can use the Nginx plugin. It looks for a suitable virtual server, validates the domain, and offers to configure HTTPS. The required ports must be accessible, Nginx must be installed and running, and the domain must point to this server.

sudo certbot --nginx -d example.ru -d www.example.ru

Include two names in the command only if both are actually used and configured. If the site does not use www, the second name is not needed. If the DNS name www points to another server or does not exist, attempting to issue a certificate for both names may fail. If port 80 is not open for HTTP-01, use another approach, such as DNS-01, if the chosen ACME client and DNS provider support automation.

When Certbot finishes, open a browser and check the certificate externally. A success message does not mean the application, redirects, and site resources are configured correctly. If the plugin changed the virtual server file, the new configuration must pass nginx -t. Then save the working configuration and note how the certificate will be renewed.

For a cautious approach, you can request a certificate without automatic installation using the command sudo certbot certonly --nginx -d example.ru, and connect the files manually. This option is convenient for non-standard configurations, but requires you to monitor reload after renewal.

7. Manually Connecting the Certificate and Private Key

Let’s Encrypt certificates issued by Certbot are usually available via symbolic links in the directory /etc/letsencrypt/live/ИМЯ-СЕРТИФИКАТА/. This is not always literally the domain name: for repeat issuance or combining names, Certbot may use a different name. The exact path is shown by sudo certbot certificates.

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.ru;

    ssl_certificate     /etc/letsencrypt/live/example.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.ru/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    root /var/www/example.ru/public;
    index index.html;
    location / { try_files $uri $uri/ =404; }
}

The configuration serves as a template for a static site; it should not be used as a ready-made file for WordPress or a service behind a reverse proxy. The path privkey.pem contains the private key and must not be placed in the public site directory, an analytics system, or a public repository. This file requires restricted permissions, but the Nginx master process must be able to read it.

After manually connecting the files, run sudo nginx -t && sudo systemctl reload nginx. If Nginx does not start, first check the paths, permissions, key and certificate compatibility, and whether there are identical conflicting blocks. Do not copy the key into the directory public to simplify permissions.

8. HTTP → HTTPS: Redirect Correctly Without an Infinite Loop

Moving from HTTP to HTTPS: Redirects and Security Checks
Moving from HTTP to HTTPS: Redirects and Security Checks. Custom thematic illustration; interfaces are illustrative.

After installing the certificate, old addresses of the form http://example.ru/page should lead to https://example.ru/page. A permanent redirect helps users and search engines choose the secure version. HTTP status 301 is often suitable for a regular website; status 308 preserves the request method, but during migration you should consider application compatibility and the specifics of POST requests.

server {
    listen 80;
    listen [::]:80;
    server_name example.ru www.example.ru;
    return 301 https://example.ru$request_uri;
}

This example explicitly sets the canonical host example.ru. It does not use the uncontrolled value $host to form the target domain. If the certificate also covers www.example.ru, you can create a separate HTTPS block that redirects www to the main address. But any such block on port 443 must first have a valid certificate for the name the visitor enters: the browser checks TLS before receiving the HTTP redirect.

Do not configure contradictory rules simultaneously in Nginx, a CDN, and the CMS. A typical failure occurs when a proxy accepts HTTPS, passes HTTP to the application, and the application redirects the visitor to HTTPS again. When configuring a reverse proxy, you must correctly pass information about the original connection scheme, and the application should trust only known proxies.

9. TLS 1.3, TLS 1.2, and Modern Security Settings

TLS 1.3 Encryption Between the Browser and the Nginx Server
TLS 1.3 Encryption Between the Browser and the Nginx Server. Custom thematic illustration; interfaces are illustrative.

TLS 1.3 is recommended for a modern public website, along with TLS 1.2 if compatibility with older clients is required. Do not re-enable the old SSLv3, TLS 1.0, or TLS 1.1 protocols without a compelling reason: their use is associated with outdated security mechanisms. In current versions of Nginx and OpenSSL, secure defaults have improved, so manually copying dozens of ciphers from an old article is often worse than using the standard settings.

ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

These directives show a common set of parameters, but the exact configuration should be chosen based on the installed Nginx and OpenSSL versions, the architecture, and the site's audience. The directive ssl_ciphers primarily controls cipher suites for TLS 1.2 and earlier versions; TLS 1.3 uses different rules. Do not try to improve security by simply adding a long ssl_ciphers without checking that clients still work.

HTTP/2 support should be checked separately. In current versions of Nginx, the directive http2 on; is used in the appropriate context to enable it, provided the module is available. The old entry listen 443 ssl http2; may trigger a warning about deprecated syntax in newer builds, while newer syntax may not be supported in older versions. Therefore, the command nginx -v is more important than a universal example from the internet.

10. HSTS: Strengthening HTTPS Without Blocking Subdomains

The header Strict-Transport-Security tells the browser to open the site only over HTTPS from then on. It protects against some attacks during the transition from HTTP, but requires caution. If the certificate breaks or HTTPS becomes unavailable, a browser that has stored HSTS may not let the user bypass the error by switching to regular HTTP.

For a new site, it is sensible to start with a short duration, check that the main pages work, and only then increase max-age. The directive includeSubDomains extends the policy to subdomains: do not enable it until technical panels, webmail interfaces, and other addresses in use are protected. preload requires separate preparation and should not be added automatically.

add_header Strict-Transport-Security "max-age=300" always;

This is a starter test example for five minutes. After successful testing and once the entire infrastructure is ready, the duration can be increased in accordance with official recommendations. The header must be sent over HTTPS; it does not fix a broken certificate. Before implementing HSTS, make sure there are no conflicting headers from Nginx, the application, and the CDN.

11. Certificate Chain, fullchain.pem, and File Permissions

Error ERR_CERT_AUTHORITY_INVALID is often related not to a missing certificate, but to an incorrect chain. The server sends the site certificate and the necessary intermediate certificates so the browser can verify the digital signatures up to a trusted root. In a typical Certbot setup, the file fullchain.pem handles this, whereas cert.pem contains only the end-entity certificate.

The private key is stored separately. The web server needs access to it when starting up and reloading the configuration, but making the key readable to all system users is not acceptable. When working with containers and secret stores, it is better to manage access through controlled mechanisms rather than embedding the key in a public Docker image.

sudo certbot certificates
sudo nginx -t
openssl s_client -connect example.ru:443 -servername example.ru -showcerts </dev/null

The last command is useful for checking the actual chain served by the server. Copying a certificate from the screen and comparing it with the file in the control panel is unreliable: the CDN, load balancer, and origin Nginx may have different certificates. You need to know exactly where in the connection the TLS handshake takes place.

12. Checking the Configuration and Safely Reloading Nginx

After each change, check the syntax first. The command nginx -t does not guarantee that every page on the site will work, but it can detect missing files, invalid directive contexts, and many configuration failures before the changes are applied. Only after it succeeds should you perform a graceful reload using systemctl reload nginx.

sudo nginx -t && sudo systemctl reload nginx
sudo systemctl status nginx --no-pager
sudo journalctl -u nginx -n 60 --no-pager

These commands are intended for systems with systemd. In a container environment, the service may be managed differently: use the standard method for sending Nginx a reload signal. If errors occur after changes, restore the backup and check the logs. Do not stop the service with the command restart“just in case” if a proper reload is sufficient, especially on a busy production site.

It is also useful to check that the server responds over both protocols and that requests for pages, images, and CSS are served without errors. In large projects, test the configuration in a staging environment or on a standby load balancer node first; changing all servers at once increases the risk of downtime.

13. Certbot Automatic Renewal and Timer Check

A public certificate has a limited validity period. As of March 15, 2026, the maximum validity period for new public TLS certificates under the CA/Browser Forum baseline requirements is 200 days; as of March 15, 2027, it is set to decrease to 100 days, and as of March 15, 2029, to 47 days. Some certificate authorities issue certificates with a slightly shorter validity period. As a result, manual renewal without monitoring is becoming less and less reliable.

Certbot usually sets up an automatic renewal task using a systemd timer or cron, depending on the installation method. Check that the task exists, then run a renewal test. The command renew determines on its own which certificates are nearing expiration, so there is no need to force renewal every day.

sudo certbot certificates
sudo certbot renew --dry-run
systemctl list-timers --all | grep -i certbot

When files are connected manually, Nginx must reload the renewed certificate after a successful issuance. You can use deploy hook, which runs only after a successful renewal. The specific location for hooks depends on the Certbot installation; a traditional setup uses the directory /etc/letsencrypt/renewal-hooks/deploy/. The script must be executable, have restricted permissions, and be tested in advance.

# Пример команды внутри deploy-hook после успешного выпуска:
/usr/sbin/nginx -t && /bin/systemctl reload nginx

If Certbot already manages reloads through a plugin or the hosting provider, a duplicate hook may not be necessary. The goal is not to have as many tasks as possible, but to ensure the new certificate is actually served to visitors. An external check of the certificate's expiration date after renewal is essential.

14. Checking with curl, OpenSSL, and SSL Labs

Three independent sources are useful for troubleshooting: the HTTP response, the TLS certificate, and an external configuration assessment. curl checks that the connection can be established and follows redirects, OpenSSL shows technical details about the certificate and connection, and SSL Labs tests the public server using its own test scenarios.

curl -I http://example.ru
curl -Iv https://example.ru
curl -L -I http://example.ru
echo | openssl s_client -connect example.ru:443 -servername example.ru 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

When running the command curl -L -I , note that some applications respond differently to HEAD than to GET. If in doubt, repeat the check with a regular request. The option -k or --insecure must not be used as proof of security—it disables certificate verification.

To check TLS 1.3, you can run openssl s_client -connect example.ru:443 -servername example.ru -tls1_3. Success also depends on the capabilities of the local OpenSSL version. From outside, check the main address, the wwwversion, the API, and any subdomains in use; if there are multiple IP addresses, check the different network paths as well.

15. Nginx as a Reverse Proxy: HTTPS in Front of the Application

Nginx often terminates the TLS connection and forwards requests to the application on a local port. This is a common architecture for websites: visitors communicate with Nginx over HTTPS, while the application behind it can run on a separate private network. However, if the backend is outside the trusted local network, the connection from Nginx to the application should also be secured separately.

server {
    listen 443 ssl;
    server_name example.ru;
    ssl_certificate /etc/letsencrypt/live/example.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.ru/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

The example assumes that the application trusts only the Nginx serving it and that port 3000 is not accessible from the external network. In a complex infrastructure, the client's original address and the X-Forwarded-* headers should be handled according to the specific list of trusted proxies. These headers must not be considered trustworthy if an arbitrary client can forge them.

If a CDN sits between the browser and Nginx, determine where TLS terminates and how the CDN connects to the origin server. Modes that leave an unencrypted segment before the origin can create unnecessary risks. Even with a valid certificate on the public-facing side, make sure separately that the origin cannot be accessed through an unprotected bypass route.

16. Why You Shouldn't Enable OCSP Stapling, Ciphers, and Optimizations Blindly

Older instructions almost always include enabling OCSP stapling without explaining whether the chosen certificate and specific Nginx version support this setup. In practice, the mechanism depends on the availability of OCSP responses, the chain, and DNS. Some certificate authorities and products change how revocation information is handled. Therefore, there is no need to add ssl_stapling on; just to satisfy a formal checklist.

Similarly, configuring cipher suites requires understanding TLS versions and compatibility goals. Copying the “strictest” set from the internet may make the site inaccessible to devices that its audience still needs to use. Use current recommendations and the results of checking the existing configuration as your guide, not the number of lines in the configuration file.

On a high-performance web server, you can separately explore TLS session caching, HTTP/2, HTTP/3, handshake speed, and the amount of data transferred. But first, make sure HTTPS works reliably and renewals are automatic. Without these, speed optimizations do not solve the main problem.

17. Mixed Content and Errors After Moving a Site to HTTPS

After installing a certificate, some pages may look wrong: styles fail to load, scripts break, or images disappear. The most common reason is that an HTTPS page requests resources using the old address http://. This is called Mixed Content. Browsers usually block insecure scripts and styles, and may try to automatically change the address to HTTPS for some resources.

The correct fix is to update the original URLs in templates, configuration, the database, and third-party integrations. Do not rely on the browser to always fix the error itself. If the site runs WordPress, you need to check home, siteurl, plugins, the theme, and saved URLs separately. A broad text replacement in the WordPress database can damage serialized data, so it is safer to use suitable tools and backups.

Detailed steps are provided in the articles “Mixed Content Error” and “SSL for WordPress”. It is important to distinguish an invalid certificate from mixed content: the former prevents a trusted connection from being established, while the latter appears only after the HTTPS page has loaded.

18. Common Nginx errors and troubleshooting sequence

Incorrect file path. During validation, Nginx reports that it cannot open the certificate or key. Verify the path to certbot certificates, that the file exists, and the file permissions. Do not create an empty file at the specified path: it cannot replace the certificate.

The domain received someone else’s certificate. Check server_name, SNI, DNS, and the default server. With multiple virtual hosts, the error may occur only for a specific name or IPv6 address. The check is performed with -servername in OpenSSL.

Certbot could not validate the domain. Possible causes include an incorrect DNS record, port 80 being closed, a proxy intercepting the validation URL, or an incorrect configuration block. Wildcards require a supported DNS-01 challenge; regular HTTP-01 cannot issue a wildcard certificate.

Infinite redirect loop. Check the rules on the CDN, in Nginx, and in the application. Determine which component first returns Location, and fix the conflict rather than disabling HTTPS.

The certificate was renewed, but the browser sees the old one. After issuance, verify that Nginx has reloaded the files and that a load balancer or CDN is not serving its own outdated certificate. Check each server in a cluster individually.

19. SEO after switching to HTTPS: canonical URLs, sitemap, and links

Search engines need to know which URL is the primary one. A certificate alone is not enough: use a single domain variant, permanent redirects from old HTTP URLs, correct canonical links, and an up-to-date sitemap. Internal links should not continue to point to old HTTP pages, even if the redirect works.

After the switch, check the files robots.txt and sitemap.xml, links to images, CSS, JavaScript, and pages with different trailing-slash variants of the URL. Sites with a long publishing history require special attention: outdated links may remain in templates, data files, RSS, Open Graph, and social media snippets.

HTTPS is a technical requirement of the modern web platform, but it does not guarantee higher rankings on its own. Stable indexing depends on site availability, content quality, and correct handling of existing URLs.

20. Step-by-step checklist for a safe launch

CheckHow to perform the checkWhat counts as a successful result
DNSA and AAAA records for all names in useAll addresses point to the correct infrastructure
Ports80 for ACME HTTP-01, 443 for HTTPSAccessible from an external network
BackupConfiguration and rollback method savedThere is a known way to restore the previous version
CertificateSAN, validity period, issuer, fullchainCovers all required names
Nginxnginx -t and graceful reloadNo configuration errors
Redirectcurl -L -I from an HTTP URLNo loops or redirects to another domain
ContentBrowser console, Network, key pagesNo Mixed Content or broken resources
Renewalcertbot renew --dry-run, timerTest succeeds and monitoring is working
External checkOpenSSL and SSL LabsThe actual server serves the correct chain

The checklist does not require installing additional plugins or changing settings without a reason. It helps separate checks of the network, certificate, configuration, and application. If a problem is found at any step, fix that specific issue first. This approach reduces the risk of downtime when migrating a live site.

21. Frequently asked questions about SSL on Nginx

Can I use a free certificate for a commercial website?

Yes. A trusted Let’s Encrypt DV certificate provides full encryption when TLS is configured correctly. The differences between OV and EV primarily concern organization validation, not the “strength” of HTTPS.

Do I need to stop Nginx to issue a Let’s Encrypt certificate?

When using the plugin --nginx usually not. The standalone mode may require freeing up port 80; it is not needed for every scenario.

Why was the certificate issued for example.ru, but www does not load?

The certificate’s SAN may not include www.example.ru, or DNS may point it to another server. Check both names separately.

Can I use TLS 1.3 only?

Technically, sometimes yes, but some clients will lose access. Before making this decision, analyze your actual audience and test compatibility.

Is HSTS required?

It is a useful mechanism, but it should be introduced gradually. It is especially risky to enable includeSubDomains and preload.

Why does Nginx serve the previous certificate after renewal?

The server may not have reloaded the updated files, or HTTPS may terminate at a CDN/load balancer. Check externally which certificate is actually being served.

Can I use one certificate for several websites?

Yes, if all required names are included in the SAN or covered by a valid Wildcard. When sharing a private key, consider the shared risk of its compromise.

Do I need to change the permissions on privkey.pem?

The key must be protected from unauthorized reading but accessible to the Nginx master process. Set permissions according to the specific system; do not make the key readable by all users.

22. Conclusion and official sources

Installing SSL on Nginx involves a sequence of tasks involving DNS, virtual servers, the certificate, and automation. First, check that the domain is reachable, then issue a certificate, and then configure HTTPS, permanent redirects, and secure TLS settings. Finish with an independent external check and a test renewal.

The key practical takeaway: a secure website is not just the presence of fullchain.pem on disk. Every required domain name must have working HTTPS, Nginx must use the correct files, and automatic renewal must run without manual intervention. This prevents certificate expiration from becoming a constant threat to site availability.

Official sources for checking settings:

Updated November 5, 2026. Before making changes to a production server, check the steps against the versions of Nginx, OpenSSL, and the installed ACME client.

IP Geolocation by DB-IP