How to force HTTPS and redirect HTTP
Updated 7/20/2026
An SSL certificate does not help if visitors can still reach the insecure HTTP version. Redirect all traffic to HTTPS.
Nginx
Add a server block listening on port 80 that redirects:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
nginx -t && systemctl reload nginx
Apache
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
Force HTTPS going forward (HSTS)
Add a header telling browsers to always use HTTPS for your domain:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
If you do not have a certificate yet, see Free SSL certificate with Let's Encrypt.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Web servers
How to optimize Nginx performance: gzip, cache and HTTP/2
Make your site faster with gzip compression, static file caching and HTTP/2, a few lines of config.
Updated 7/20/2026Web serversHow to install phpMyAdmin to manage MySQL from the browser
Manage your MySQL databases from a web interface with phpMyAdmin, installed and secured correctly.
Updated 7/20/2026Web serversHow to host a static site or a React/Vue app
Publish a static site or a React/Vue build on Nginx, with correct routing for single-page apps.
Updated 7/20/2026