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

前端 未结 8 1373
滥情空心
滥情空心 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 03:15

    You may try to set the server IP address in:

    /etc/nginx/conf.d/default.conf
    

    So it looks like this:

    server {
        listen 80;
        server_name localhost IP.OF.VPS.HERE;
    

    Then you can specify the subdomain vhost, like:

    server {
            listen 80;
            server_name subdomain.domain.com;
    

    And the main domain, like:

    server {
            listen 80;
            server_name www.domain.com domain.com;
    

    Then restart Nginx:

    /etc/init.d/nginx restart
    

    Each vhost should have its own *.conf file (for better organization), like:

    /etc/nginx/conf.d/subdomain.domain.com.conf
    /etc/nginx/conf.d/domain.com.conf
    /etc/nginx/conf.d/default.conf
    
    0 讨论(0)
  • 2021-01-31 03:15
    if ($http_host != "example.com") {
        return 301 https://example.com;
    }
    
    0 讨论(0)
提交回复
热议问题