How to Enable and Verify TLS 1.3 in Nginx on FreeBSD 15
TLS 1.3 is on by default in Nginx on current FreeBSD. Set up the HTTPS server block, verify the protocol, and tune TLS 1.3-only mode, cipher suites and 0-RTT.
This guide sets up Nginx on FreeBSD 15 with TLS 1.3, shows how to confirm that clients really negotiate it, and covers the settings that are specific to TLS 1.3: restricting the server to that version, choosing cipher suites and enabling 0-RTT. The same steps apply to FreeBSD 14.
FreeBSD 12 reached end of life at the end of 2023. On that release TLS 1.3 was new and had to be switched on. Today it works out of the box: the Nginx package is built against the OpenSSL 3 library in the FreeBSD base system, and Nginx has enabled TLS 1.3 by default since version 1.23.4. If you have not set ssl_protocols yourself, an HTTPS site on a current FreeBSD server already offers TLS 1.2 and TLS 1.3.
Requirements
- A server running a supported FreeBSD release (15.x or 14.x) and root access, directly or through
sudoordoas. The commands below are run as root. - A domain name,
example.comin the examples, withAand/orAAAArecords pointing to the server. - TCP ports 80 and 443 open in your firewall.
Update the system and install Nginx
Apply pending base-system patches and package updates first, so that you run the current OpenSSL fixes:
freebsd-update fetch install
pkg update && pkg upgrade -yInstall Nginx, enable it at boot and start it:
pkg install -y nginx
sysrc nginx_enable=YES
service nginx startCheck what you have:
nginx -VThe output shows the Nginx version and a line such as built with OpenSSL 3.x. TLS 1.3 needs Nginx 1.13.0 and OpenSSL 1.1.1 or newer; every supported FreeBSD release is well past both. The same line tells you whether your package uses the base OpenSSL or one from ports.
Get a certificate
Any valid certificate works. This example uses Certbot with the webroot method, which leaves the running Nginx untouched. The default document root of the FreeBSD package is /usr/local/www/nginx.
pkg install -y security/py-certbot
certbot certonly --webroot -w /usr/local/www/nginx -d example.comOn FreeBSD, Certbot stores its files under /usr/local/etc/letsencrypt. The certificate chain is /usr/local/etc/letsencrypt/live/example.com/fullchain.pem and the key is privkey.pem in the same directory. Read the message that pkg prints after installing Certbot: it explains how to enable automatic renewal through periodic.
Configure the HTTPS server block
The main configuration file is /usr/local/etc/nginx/nginx.conf. Open it:
vi /usr/local/etc/nginx/nginx.confInside the http { } block, next to the existing port 80 server, add:
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name example.com;
root /usr/local/www/nginx;
index index.html;
ssl_certificate /usr/local/etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /usr/local/etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
}ssl_protocols TLSv1.2 TLSv1.3; is the built-in default and is written out here only to make the choice visible. The http2 on; directive needs Nginx 1.25.1 or newer; the standalone ssl on; directive found in old configurations has been removed, so use the ssl parameter of listen as shown.
Test the configuration and reload:
nginx -t
service nginx reloadIf you filter traffic with PF, make sure /etc/pf.conf lets HTTPS in, for example with a rule like this, and reload the ruleset with pfctl -f /etc/pf.conf:
pass in proto tcp to port { 80 443 }Verify that TLS 1.3 is negotiated
From the server or any machine with OpenSSL, force a TLS 1.3 handshake:
openssl s_client -connect example.com:443 -servername example.com -tls1_3 -brief < /dev/nullA successful run prints Protocol version: TLSv1.3 and the cipher suite, typically TLS_AES_256_GCM_SHA384. With curl:
curl -sv --tlsv1.3 -o /dev/null https://example.com/ 2>&1 | grep -i 'SSL connection'In a browser, the developer tools show the protocol version in the security details of the connection.
To see which version your visitors use, add the variables $ssl_protocol and $ssl_cipher to a log format in the http { } block and use it for the site's access log:
log_format tls '$remote_addr [$time_local] "$request" $status $ssl_protocol $ssl_cipher';
access_log /var/log/nginx/tls.log tls;Optional TLS 1.3 settings
Allow only TLS 1.3
All current browsers support TLS 1.3, but older API clients, monitoring agents and embedded devices may only speak TLS 1.2. Check the log above for a few days before you drop it. Then change the directive to:
ssl_protocols TLSv1.3;The protocol version is negotiated before Nginx knows which site the client asked for, so the value of the default server for an address and port can apply to every name-based virtual host on it. Set the directive once in the http { } block rather than in a single site.
Choose cipher suites
The ssl_ciphers directive only affects TLS 1.2 and older. The TLS 1.3 suites are a separate, short list in which every entry is considered strong, and the defaults are a sound choice. If a policy requires a specific list, pass it to OpenSSL with ssl_conf_command, available since Nginx 1.19.4:
ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256;List the suites your OpenSSL offers with:
openssl ciphers -v -tls1_30-RTT early data
TLS 1.3 lets a returning client send its first request together with the handshake. Nginx keeps this off by default because early data can be replayed by an attacker. Enable it only if every request that can arrive this way is safe to repeat, and pass the information on to your application so it can reject anything else:
ssl_early_data on;
proxy_set_header Early-Data $ssl_early_data;Troubleshooting
- The TLS 1.3 test fails but TLS 1.2 works: search the configuration for an older
ssl_protocolsline that omitsTLSv1.3, including in files pulled in withinclude:grep -rn ssl_protocols /usr/local/etc/nginx/. Check the default server for the address and port first. nginx -treports an unknown directivehttp2: the installed Nginx is older than 1.25.1. Upgrade the package, or uselisten 443 ssl http2;on that version.- A proxy or load balancer in front of the server: the TLS version the client sees is decided by whatever terminates TLS first. Test against the server directly to check Nginx itself.
- Changes have no effect: a reload is skipped when the configuration has an error. Run
nginx -tand look at/var/log/nginx/error.log.
The directives used here are documented in the Nginx SSL module reference.
Frequently asked questions
Do I have to build Nginx or OpenSSL from ports to get TLS 1.3?
No. The binary package from pkg is sufficient. Building from ports is only useful if you need a module or option that the default package does not include.
Should I disable TLS 1.2?
TLS 1.2 with modern cipher suites is still considered secure, and clients that support both versions pick TLS 1.3 automatically. Keep TLS 1.2 unless a compliance rule tells you otherwise or your logs show that nothing uses it. TLS 1.0 and 1.1 are deprecated and are already excluded by the default ssl_protocols value.
Does HTTP/3 need anything beyond TLS 1.3?
HTTP/3 runs over QUIC, which always uses TLS 1.3, but it is configured separately: a listen 443 quic socket, UDP port 443 opened in the firewall and an Alt-Svc header. Having TLS 1.3 enabled for TCP connections does not switch HTTP/3 on.
Why does an online scanner still list TLS 1.2 after I set ssl_protocols TLSv1.3?
Usually because another server block is the default server for port 443 and still allows TLS 1.2, or because a CDN or load balancer in front of the server terminates TLS with its own settings. Set ssl_protocols once at http level, reload, and test the server directly with openssl s_client -tls1_2, which should now fail.