- Configure NGINX to serve
example.comover HTTP/HTTPS - Use
allow/denydirectives for static IP filtering - Automate bans on repeated auth failures with Fail2Ban
- An NGINX server on ports 80 & 443
- Two clients: node01 (
192.231.128.12) and node02 (192.231.128.3)

Prerequisites
- Ubuntu Server with NGINX installed
- Root or sudo access to
/etc/nginxand/etc/fail2ban - A self‐signed or valid SSL certificate for
example.com
1. Configure NGINX for HTTPS and Basic Auth
Create or edit/etc/nginx/sites-available/example-https:
2. Test Connectivity from Clients
- On the NGINX server, find its IP:
- On node01 and node02, add to
/etc/hosts:
Make sure no conflicting DNS entries exist for
example.com.- Run these tests on each node:
| Test | Command | Expected Response |
|---|---|---|
| HTTP → HTTPS redirect | curl http://example.com | 301 Moved Permanently |
| HTTPS (self-signed) | curl https://example.com | SSL certificate error |
| Skip cert validation | curl -k https://example.com | HTML of index.html |
Access /admin header | curl -k --head https://example.com/admin | HTTP/1.1 401 Unauthorized |
3. Block a Single IP with deny
To block node02 globally, edit the / location:
- node01 (
192.231.128.12): - node02:
4. Restrict /admin to a Single Host
Allow only node01 to hit /admin:
- node02 →
403 Forbidden - node01 →
401 Unauthorized(prompt for credentials)
5. Allow a CIDR Range
To permit both nodes (in192.231.128.0/24) and block everyone else:

6. Automate Banning with Fail2Ban
Replace manual IP lists with automatic bans on repeated auth failures.- Install Fail2Ban:
If prompted to restart due to outdated libraries, choose Ok.

-
Copy the default jail configuration:
-
Enable the nginx-http-auth jail in
/etc/fail2ban/jail.local: -
Restart Fail2Ban:
-
Verify the jail status:
You should see the jail enabled with no banned IPs initially.
- Trigger a ban by entering incorrect credentials in your browser:

With NGINX’s static
allow/deny and Fail2Ban’s dynamic banning, you have a robust defense against unwanted access and brute-force attempts.