how to disable direct access to a web site by ip address

前端 未结 8 1372
滥情空心
滥情空心 2021-01-31 02:17

I have a website on a VPS.

The issue I am having is that when I enter the IP of the server, it links to the website.
Even when entering mail.domain.com, it does the

相关标签:
8条回答
  • 2021-01-31 02:48

    You can use redirect, nginx config:

    server {
            listen 80;
            server_name IP_ADDRESS;
            return 301 http://YOUR.DOMAIN;
    }
    
    0 讨论(0)
  • 2021-01-31 03:05

    You can just add a server directive before others.

    server {
        listen 80;
        server_name _;
        return 404;
    }
    
    0 讨论(0)
  • 2021-01-31 03:06

    Put this at top of your /etc/nginx/conf.d/SERVER_IP_ADDRESS.conf file and comment everything what is below it.

    #disabling accesing server by ip address
    server {
            listen SERVER_IP_ADDRESS:80 default;
            server_name _;
            return 404;
    }
    

    Then restart your Nginx server (on Ubuntu it is done by service nginx restart this command)

    Now when you will put your server's ip address to browser url field you will get 404 error.

    0 讨论(0)
  • 2021-01-31 03:06

    You can use redirect, nginx config:

    server {
            listen 80;`enter code here`
            server_name IP_ADDRESS;
            return 301 http://YOUR.DOMAIN;
    }
    
    0 讨论(0)
  • 2021-01-31 03:06

    you can return any error you find suitable. A list of errors can be found here List_of_HTTP_status_codes

    server {
        listen      x.x.x.x:80;
        server_name x.x.x.x;
        return      404;
    }  
    
    0 讨论(0)
  • 2021-01-31 03:08
    server {
        listen      80 default_server;
        listen      [::]:80 default_server;
        server_name "";
        return      444;
    }
    

    You need to specify default_server parameter so that all non available server requests goes to this server block which throws 444 error.

    444 : CONNECTION CLOSED WITHOUT RESPONSE

    ref: https://httpstatuses.com/444

    0 讨论(0)
提交回复
热议问题