Private Certificate Authority for Self-Hosted Linux Servers
A practical guide to creating a private CA, issuing a local server certificate for internal HTTPS access, and trusting it on Windows clients without public DNS or Let's Encrypt.
Purpose
Set up a trusted internal HTTPS environment for a self-hosted Linux server on a local network, using your own certificate authority instead of public certificates.
Key points
- ›A private CA is useful for home labs, internal apps, and local networks that do not need public internet trust.
- ›The root CA certificate is installed on client devices so they trust certificates signed by it.
- ›The server certificate should include the local hostname and IP in its SANs.
- ›Nginx can serve HTTPS using the server certificate and private key.
- ›This approach is simple, secure for internal use, and avoids public DNS and Let's Encrypt.
Notes
Note 1
Why a private CA is useful
A private CA is ideal when you run a server only inside your home lab or office network. Browser warnings are avoided because your Windows machine trusts the root CA certificate you created yourself.
$ openssl version$ mkdir ~/my-ca && cd ~/my-ca
Client PC -> HTTPS -> AlmaLinux ServerNo public internetNo Let's EncryptNo public DNS
Note 2
Create the root CA key and certificate
The root CA is the trust anchor. If the client trusts this certificate, any server certificate signed by it will also be trusted for internal use.
$ openssl genrsa -out rootCA.key 4096$ openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.crt
$ openssl genrsa -out rootCA.key 4096$ openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.crt
Note 3
Create a server key and certificate signing request
Generate a private key for the server and a CSR that includes the hostname and IP you will use locally. This is important because TLS checks the certificate against the name you browse to.
$ openssl genrsa -out server.key 4096$ openssl req -new -key server.key -out server.csr -config openssl.cnf
$ openssl genrsa -out server.key 4096$ openssl req -new -key server.key -out server.csr -config openssl.cnf
Note 4
Create the OpenSSL config with SANs
The configuration file must include the Subject Alternative Names. This is what makes the certificate valid for both the hostname and the LAN IP address.
$ cat > openssl.cnf <<'EOF'$ [req]$ default_bits = 4096$ prompt = no$ default_md = sha256$ req_extensions = req_ext$ distinguished_name = dn$$ [dn]$ C=QA$ ST=Doha$ L=Doha$ O=My Company$ CN=server-hostname.domain.local$$ [req_ext]$ subjectAltName = @alt_names$$ [alt_names]$ DNS.1 = server-hostname.domain.local$ DNS.2 = server-hostname$ IP.1 = 192.168.1.100$ EOF
DNS.1=server-hostname.domain.localDNS.2=server-hostnameIP.1=192.168.1.100
Note 5
Sign the server certificate with the root CA
This step turns the CSR into a real server certificate signed by your root CA. The resulting certificate can then be used by Nginx.
$ openssl x509 -req -in server.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt -days 825 -sha256 -extfile openssl.cnf -extensions req_ext
$ openssl x509 -req -in server.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt -days 825 -sha256 -extfile openssl.cnf -extensions req_ext
Note 6
Install the certificate files for Nginx
Copy the server certificate and key to the Nginx SSL directory, then restrict permissions on the private key so only root can read it.
$ sudo mkdir -p /etc/nginx/ssl$ sudo cp server.crt /etc/nginx/ssl/$ sudo cp server.key /etc/nginx/ssl/$ sudo chmod 600 /etc/nginx/ssl/server.key
/etc/nginx/ssl/server.crt/etc/nginx/ssl/server.key
Note 7
Configure Nginx for HTTPS
Nginx needs the server certificate and private key in its configuration. A simple reverse proxy setup is enough for a local Next.js or Node.js application.
$ sudo tee /etc/nginx/conf.d/local-app.conf > /dev/null <<'EOF'$ server {$ listen 443 ssl http2;$ server_name server-hostname.domain.local;$ ssl_certificate /etc/nginx/ssl/server.crt;$ ssl_certificate_key /etc/nginx/ssl/server.key;$ ssl_protocols TLSv1.2 TLSv1.3;$$ location / {$ proxy_pass http://127.0.0.1:3000;$ proxy_set_header Host $host;$ proxy_set_header X-Forwarded-Proto https;$ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;$ }$ }$ EOF$ sudo nginx -t$ sudo systemctl reload nginx
listen 443 ssl http2;ssl_certificate /etc/nginx/ssl/server.crt;ssl_certificate_key /etc/nginx/ssl/server.key;
Note 8
Trust the root CA on Windows
Copy the rootCA.crt file to your Windows PC and import it into the Trusted Root Certification Authorities store. After that, the browser will trust certificates signed by your private CA.
$ Copy-Item ~/my-ca/rootCA.crt C:/temp/rootCA.crt$ https://server-hostname.domain.local
Install CertificateTrusted Root Certification Authorities
Note 9
Verify the setup
Open the local URL in a browser. If the certificate chain is trusted, the site should load over HTTPS without browser warnings.
$ curl -vk https://server-hostname.domain.local
$ curl -vk https://server-hostname.domain.localHTTP/1.1 200 OK