Welcome to Centmin Mod Community
Become a Member

Nginx Prevent direct ip access

Discussion in 'Install & Upgrades or Pre-Install Questions' started by xaitmi, May 27, 2015.

  1. xaitmi

    xaitmi Member

    35
    3
    8
    Jan 18, 2015
    Ratings:
    +3
    Local Time:
    12:35 AM
    hi right now if someone types in my vps's ip it takes them to my site.

    how can i make it go to a different page if they arent using my domain?


    like make it go to the demodomain or something.

    thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    53,211
    12,113
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,650
    Local Time:
    2:35 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    why would you even want to do that ?

    if you do there's a few solutions at nginx - how to disable direct access to a web site by ip address - Stack Overflow

    probably best is just setup an additional server context in separate or same nginx vhost as your domain

    try 302 temp redirect first before setting 301 which is permanently cached in browser
    Code:
    server {
            listen 80;
            server_name IP_ADRESS;
            return 301 http://YOUR.DOMAIN;
    }
    or specifying hostname to allow return 403 or 302/301 redirect etc

    Code:
        if ($http_host != "YOUR.DOMAIN") {
            return 403;
        }
     
    Last edited: May 27, 2015