Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria .

If you feel this website help you, you can donate at saweria .



What I Used in This Tutorial

  1. Nginx v1.24.0 from ondrej PPA.

  2. Ubuntu 22.04.3 LTS


Problem

This Happen When You Access Your IP on Browser

This Happen When You Access Your IP on Browser

This Happen When You Access Your IP on Browser But in HTTPS

This Happen When You Access Your IP on Browser But in HTTPS

The problem was

  1. How to forbid direct IP access on your server

  2. How to forbid direct IP access with HTTPS on your server


Solution

  1. Add new nginx config, i call it ipredirect.conf

    server {
    # Bad Bot Blocker
    include /etc/nginx/bots.d/ddos.conf;
    include /etc/nginx/bots.d/blockbots.conf;
    
    server_name yourIP;
    return 403;
    location / {
        return 403;
    }
    listen 443 ssl http2 reuseport default_server;
    ssl_reject_handshake on;
    
    access_log /var/log/nginx/access/ipredirect.log;
    error_log /var/log/nginx/error/ipredirect.log;
    
    }
    
    server {
        # Bad Bot Blocker
        include /etc/nginx/bots.d/ddos.conf;
        include /etc/nginx/bots.d/blockbots.conf;
    
        listen 80;
        server_name yourIP;
        access_log /var/log/nginx/access/ipredirect.log;
        error_log /var/log/nginx/error/ipredirect.log;
    
        location / {
            return 403;
        }
    }
    
  2. Then test on your browser

It Should Return 403 Forbidden

It Should Return 403 Forbidden

It Should Return SSL Error If You Access Your IP with HTTPS

It Should Return SSL Error If You Access Your IP with HTTPS

  1. To enhanced this config, you can setup nginx bad bot blocker , so it will block bad IP
With Nginx Bot Blocker It Will Block ‘Bad IP’

With Nginx Bot Blocker It Will Block ‘Bad IP’


Reference:

  1. stackoverflow - nginx service prevents IP leaks ssl certificate