Redirect HTTP to HTTPS and Configure IP Whitelist in Nginx
This guide shows how to rewrite Nginx port 80 requests to HTTPS on port 443, configure the HTTPS server block, and set up an IP whitelist with allow and deny directives to restrict access to specific clients.
To redirect traffic from port 80 to 443, add a server block listening on 80 and use a rewrite rule that permanently redirects to the same host over HTTPS.
server {
listen 80;
server_name oa.dalu.com;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}For HTTPS, configure a server block listening on 443 with the appropriate server name, document root, and log files.
server {
listen 443;
#server_name default;
server_name oa.dalu.com;
root /data/web/;
}To restrict access to specific client IPs, create a server block with an allow list and a final deny rule.
server {
listen 80;
server_name www.test.com;
root /var/www/html/test;
access_log /var/www/logs/access.log main;
error_log /var/www/logs/error.log;
allow 100.110.15.16;
allow 100.110.15.17;
allow 100.110.15.18;
allow 127.0.0.1;
deny all;
}Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.