When deploying web applications in production, enforcing HTTPS is essential to protect data in transit and build user trust. This tutorial walks you through setting up automatic HTTP to HTTPS redirection using SafeLine WAF—a high-performance security tool built on Nginx.
✅ Prerequisite: You should already have SafeLine WAF installed. If not, check out the official installation guide:
SafeLine WAF Installation
What You’ll Need
- A valid SSL certificate (
.crt
) and private key (.key
) - A web application deployed on the same server as SafeLine WAF
1. Avoid Port Conflicts: Change Your App's Nginx Port
If your web app and SafeLine WAF are on the same server, you’ll need to avoid port conflicts. By default:
- SafeLine uses 80 (HTTP) and 443 (HTTPS)
- Your app should be moved to another port like 8000
Check available ports:
netstat -an | grep LISTEN | grep -v unix
Modify your app’s Nginx config:
In your Nginx config:
listen 8000;
Reload Nginx:
nginx -t
nginx -s reload
2. Add HTTP and HTTPS Sites in SafeLine
In the SafeLine management console:
For HTTP:
-
Port:
80
-
Upstream server:
127.0.0.1:8000
(adjust if needed)
For HTTPS:
-
Port:
443
- Enable SSL and upload your
.crt
and.key
files - Upstream server: same as HTTP
Click Submit to apply the changes.
3. Enable HTTP to HTTPS Redirection
SafeLine forwards requests using Tengine (a performance-optimized Nginx fork). You’ll need to update its forwarding configuration.
Edit the config:
cd /data/safeline/resources/nginx/sites-enabled
Find the config file for port 80 and add this line inside the server block:
rewrite ^(.*)$ https://$host$1 permanent;
Reload Nginx in the SafeLine container:
docker exec -it safeline-tengine /usr/sbin/nginx -t
docker exec -it safeline-tengine /usr/sbin/nginx -s reload
4. Test the Redirect
Now, visit your site using http://your-domain.com
in your browser.
You should be automatically redirected to https://your-domain.com
.
Final Thoughts
This configuration ensures that all HTTP traffic is securely redirected to HTTPS, eliminating mixed content warnings and increasing trust for your users. Combined with SafeLine’s intelligent threat detection, you now have a hardened entry point for your web app.
Join the SafeLine Community
If you continue to experience issues, feel free to contact SafeLine support for further assistance.
Top comments (0)