Test HTTPS on Nginx with a Self-Signed Certificate
Create a self-signed certificate with openssl, attach it to Nginx, and see what curl reports with the self-signed certificate error, -k and --cacert.
You can check an Nginx ssl setup without a public domain by using a self-signed certificate. The results below come from port 18843 and are not a substitute for a real certificate. For installing Nginx, see this guide.
[1] Create the certificate and key. -nodes leaves the key unencrypted (Nginx cannot ask for a passphrase at startup). -addext adds a subjectAltName, where current clients look for the host name.
$ mkdir -p /srv/tls-test/certs && cd /srv/tls-test$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 30 \ -keyout certs/example.key -out certs/example.crt \ -subj "/CN=example.com" -addext "subjectAltName=DNS:example.com"[2] Inspect it. For a self-signed certificate, subject and issuer are the same.
$ openssl x509 -in certs/example.crt -noout -subject -issuer -dates -ext subjectAltNamesubject=CN = example.comissuer=CN = example.comnotBefore=Oct 19 05:39:24 2026 GMTnotAfter=Nov 18 05:39:24 2026 GMTX509v3 Subject Alternative Name: DNS:example.com[3] Add listen … ssl and the certificate and key paths to a server block. A high port keeps the test away from production. The key file is -rw-------, so the user running Nginx must be able to read it.
server { listen 18843 ssl; server_name example.com; ssl_certificate /srv/tls-test/certs/example.crt; ssl_certificate_key /srv/tls-test/certs/example.key; root /srv/tls-test/www;}[4] Test the configuration and reload.
# nginx -tnginx: configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful# systemctl reload nginx[5] Call curl with verification on. --resolve points example.com at the test listener. The exit code is 60.
$ curl --resolve example.com:18843:127.0.0.1 https://example.com:18843/curl: (60) SSL certificate problem: self-signed certificateMore details here: https://curl.se/docs/sslcerts.htmlThis does not mean the Nginx config is wrong. The connection worked, but curl found no trusted CA for the certificate the server sent.
[6] -k skips verification and the response arrives. The ssl_verify_result variable of -w shows that verification was skipped, not passed. 18 is OpenSSL's code for self-signed certificate.
$ curl -sS -k --resolve example.com:18843:127.0.0.1 https://example.com:18843/ok$ curl -sS -o /dev/null -w '%{http_code} verify=%{ssl_verify_result}\n' -k \ --resolve example.com:18843:127.0.0.1 https://example.com:18843/200 verify=18[7] To pass verification without turning it off, trust that one certificate. Give --cacert the file you created and the result is verify=0.
$ curl -sS -o /dev/null -w '%{http_code} verify=%{ssl_verify_result}\n' \ --cacert certs/example.crt --resolve example.com:18843:127.0.0.1 https://example.com:18843/200 verify=0[8] If the name in the certificate differs from the address you connect to, --cacert still fails. This certificate has only DNS:example.com, so connecting by IP gives:
$ curl --cacert certs/example.crt https://127.0.0.1:18843/curl: (60) SSL: no alternative certificate subject name matches target host name '127.0.0.1'Analyze your Nginx log in the browser ↗ — nothing is uploaded.
Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.