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:
    2:32 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

    30,168
    6,784
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    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