Skip to content

Instantly share code, notes, and snippets.

@HuakunShen
Last active March 13, 2021 07:39
Show Gist options
  • Save HuakunShen/c5555950e3885085077e36837f352556 to your computer and use it in GitHub Desktop.
Save HuakunShen/c5555950e3885085077e36837f352556 to your computer and use it in GitHub Desktop.
HTTPS on Non-Default Port (Nginx)

HTTPS on Non-Default Port

Obtain an SSL certificate, https://zerossl.com/ is an option.

Get the following 3 files

  • ca_bundle.crt
  • certificate.crt
  • private.key

Combine the certificates

cat ca_bundle.crt certificate.crt > certificate-combined.crt

Nginx configuration

server {
    listen 8080 default_server;
    listen [::]:8080 default_server;

    listen 8443 ssl default_server;
    listen [::]:8443 ssl default_server;

    ssl on;

    ssl_certificate      /root/certificate-combined.crt;
    ssl_certificate_key  /root/private.key;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name <domain.com>;

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

    location ^~ /static/ {
            root /data/;
            autoindex on;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment