Configure Your First Local Nginx HTTPS Server
A minimal HTTPS service
This example uses a private disposable Linux VM, a patched Nginx build containing ngx_http_ssl_module, OpenSSL and curl. Use the chapter-19 lab README to generate short-lived test material before starting. The following server fragment assumes an enclosing http block, a dedicated prefix and existing certificate files. It is not a standalone nginx.conf.
server { listen 127.0.0.1:18201 ssl; server_name catalog.test; ssl_certificate certs/server.pem; ssl_certificate_key certs/server.key; location = /health { return 200 "catalog ok\n"; }}The ssl listener flag enables TLS on that socket. The certificate file contains public identity material, while the key file must be readable by the master process and protected from other users. Paths here are relative to the lab configuration prefix, not to the web document root. The lab has no public DNS or public listener. The old ssl on directive was removed in 1.25.1; use listen with ssl.
Choose a protocol and session policy
ssl_protocols TLSv1.2 TLSv1.3;ssl_session_cache shared:lab_sessions:1m;ssl_session_timeout 5m;ssl_session_tickets off;The protocol list allows TLS 1.2 and 1.3, provided the binary and linked library support them. TLS 1.3 requires an eligible build and library (OpenSSL 1.1.1 or later for the documented support). Set protocol policy at the http level because handshake settings can be taken from the default virtual server before SNI-based selection. Do not copy obsolete protocol or cipher settings from an old tutorial.
A session cache can reduce work when clients resume TLS sessions across connections. A shared cache is accessible to workers. The session timeout limits reuse of session parameters, not the HTTP response duration. The small cache and disabled tickets are teaching choices, not a universal tuning recipe. Session reuse depends on negotiated protocol and client behavior; this lab does not claim to demonstrate it.
Generate private fixtures and validate syntax
python3 generate_certs.pypython3 verify_offline.pymkdir -p run logs tmp/client tmp/proxy tmp/fastcgi tmp/uwsgi tmp/scginginx -p "$PWD/" -c "$PWD/nginx.conf" -tThe generator creates a CA and a leaf with a DNS SAN for catalog.test, using restrictive permissions. It refuses to overwrite a certificate directory. The offline checks exercise certificate validation and key matching. A successful configuration test additionally confirms that this binary can parse the config and open the referenced files; it does not prove that the listener can start or that a client will trust it. Start only in the approved non-root VM as shown in the lab README.
Verify the local server from a client
curl -q --noproxy "*" --max-time 5 --cacert certs/ca.pem \ --resolve catalog.test:18201:127.0.0.1 \ https://catalog.test:18201/healthThe URL still supplies catalog.test for TLS identity checking and the HTTP host, while --resolve sends the connection to the loopback address. --cacert supplies trust only for this invocation; no system trust store changes are needed. Do not distribute the lab CA private key or install its root permanently. A successful response proves the tested connection and route, not a production security audit.
Practice
Explain which changes require a new certificate: a different DNS name, a new port, or a new document root. Then test the correct name and a mismatched name using the chapter lab. The certificate remains valid for the same DNS identity on a different port, assuming the rest of the policy still passes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Configure Your First Local Nginx HTTPS Server
Create a loopback TLS listener with a disposable CA, a correctly named certificate, and explicit protocol policy.
Which listener enables TLS in modern Nginx?
How should a PEM chain file be ordered?
What does ssl_session_timeout govern?
What does curl --resolve change in this lab?
What does a successful nginx -t establish?