Security

HTTP vs HTTPS: How TLS Works, Free SSL Certificates and HSTS Explained

By NileVPS Team · Published · 5 min read

اقرأ المقال بالعربي

Every time a browser loads a page, it speaks HTTP, the protocol of the web. Plain HTTP sends everything as readable text: the pages, the forms, the cookies that keep you logged in. Anyone on the path between the visitor and the server, such as a public Wi-Fi operator or a compromised router, can read or even modify that traffic. HTTPS is the same HTTP, wrapped inside an encrypted TLS connection. Today it is the expected default: browsers label plain HTTP pages as "Not secure", and many modern web features only work over HTTPS. This article explains the difference and shows how to enable HTTPS on your own server for free.

What HTTPS actually protects

TLS (Transport Layer Security, the successor of SSL) provides three guarantees:

  • Confidentiality: the content is encrypted, so eavesdroppers see only scrambled data.
  • Integrity: any modification in transit is detected, so nobody can inject ads or malicious scripts into your pages.
  • Authentication: the certificate proves the visitor is talking to the real owner of the domain, not an impostor.

What HTTPS does not do is make the website itself safe. A site with a valid certificate can still have vulnerable code or be run by a scammer. The padlock means the connection is private, not that the content is trustworthy.

HTTP vs HTTPS at a glance

HTTPHTTPS
Default port80443
EncryptionNoneTLS
Protection against tamperingNoYes
Browser label"Not secure"Padlock / secure
HTTP/2 and HTTP/3 in browsersNot availableAvailable
Certificate neededNoYes (can be free)

How a TLS connection starts

When a browser connects to https://example.com, a short handshake happens first. The browser sends the TLS versions and ciphers it supports, together with the hostname (SNI). The server replies with its certificate and key-exchange data. The browser checks that the certificate is valid for that hostname, has not expired and is signed by a trusted certificate authority. Both sides then derive shared session keys, and all further data is encrypted with fast symmetric encryption. With TLS 1.3, this setup needs only one round trip, so the performance cost on modern hardware is small.

Getting a free certificate with Let's Encrypt

Let's Encrypt is a non-profit certificate authority that issues free, automatically renewable certificates trusted by all major browsers. On a VPS running Ubuntu or Debian with Nginx, the usual tool is Certbot. First make sure your domain's DNS A record (and AAAA, if you use IPv6) points to the server and that ports 80 and 443 are open in the firewall. Then:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Certbot proves you control the domain, obtains the certificate, edits your Nginx server block and can set up the redirect from HTTP to HTTPS. Certificates are valid for a limited period and are renewed automatically by a systemd timer; confirm that renewal works with:

sudo certbot renew --dry-run

For Apache, use the python3-certbot-apache plugin with --apache. If you use Caddy as a web server, it obtains and renews certificates automatically without extra tools.

Redirect all HTTP traffic to HTTPS

Keep port 80 open, because visitors still type addresses without https:// and Let's Encrypt can use it for validation, but redirect everything:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

A sensible TLS block for the HTTPS server:

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;

TLS 1.0 and 1.1 are deprecated and should stay disabled. After any change, run sudo nginx -t and then sudo systemctl reload nginx.

HSTS: telling browsers to always use HTTPS

Even with a redirect, the very first request may go over plain HTTP. HTTP Strict Transport Security (HSTS) fixes this: once a browser has seen the header, it will use HTTPS for that domain automatically for the time you specify.

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Roll it out carefully. Start with a short max-age such as 300 seconds, confirm that every subdomain works over HTTPS, then increase it. Add includeSubDomains only when all subdomains support HTTPS, and consider the browser preload list only when you are sure you will never need plain HTTP again, because removal takes a long time.

Common problems after switching

  • Mixed content: the page loads over HTTPS but includes images or scripts via http://. Browsers block or warn about them. Update links to https:// or use relative paths, and fix hard-coded site URLs in your CMS settings.
  • Redirect loops: often caused by a proxy or CDN in front of the server that talks to it over HTTP while the app forces HTTPS. Make sure the app trusts the X-Forwarded-Proto header from the proxy.
  • Expired certificates: usually a broken renewal timer or a firewall that blocks port 80. Monitor certificate expiry with your uptime tool.

HTTPS is one important part of protecting a site; our guide on protecting your website from attacks covers the application side. If you need a server to host it, see our VPS plans and pricing.

FAQ

Is a free Let's Encrypt certificate less secure than a paid one?

No. The encryption strength is the same. Paid certificates can offer organization validation, longer support options or warranties, but for encrypting traffic and showing the padlock, a free domain-validated certificate is just as strong.

Does HTTPS make my website slower?

On modern servers the cost is minimal, especially with TLS 1.3 and session resumption. In practice HTTPS often makes sites faster, because browsers only use HTTP/2 and HTTP/3 over encrypted connections.

Do I need HTTPS if my site has no login or payment forms?

Yes. Without HTTPS, anyone in the network path can alter your pages, inject scripts or track which pages visitors read. Browsers also mark such pages as not secure, which hurts visitor trust.

Related guides