nginx:我不拥有的域名指向我的网站

nginx:我不拥有的域名指向我的网站

我刚刚注意到一个随机域名指向我拥有的一个网站,并且该网站可以通过该随机域名完全访问。有办法解决这个问题吗?

我使用 nginx 作为 Web 服务器,主机通过域名解析。此外,我还使用 CloudFlare 来管理网站。

我知道任何人都可以将域指向任何内容,但可能有办法处理它。

我已经为我的 nginx 默认服务器设置了此配置,但该域仍然通过:

server {
    listen      80 default_server;
    server_name _;
    return      444;
}

更新:所有服务器配置(删除/编辑不相关的部分)

server {
    #listen 443 ssl http2;
    listen 80; # http2;
    server_name domain1.tld www.domain1.tld;
    root /usr/share/nginx/domain1.tld/public;
    index index.php index.html index.htm;
    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
         # root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on the php-fpm socket
    location ~ \.php$ {
            try_files $uri @missing;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
        }

}
server {
    #listen 443 ssl http2;
    listen 80; # http2;
    server_name domain2.tld;
    root /usr/share/nginx/domain2.tld/public;
    index index.php index.html index.htm;
    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          #root /usr/share/nginx/html;
    }

}
server {
    listen 80;

    root /usr/share/nginx/domain3.tld/public;
    index index.php index.html index.htm;
    server_name domain3.tld;
    include /etc/nginx/snippets/restricted;
    location / {
        try_files $uri $uri/ /index.php;
    }

}

server {
  listen 80;
  #listen 443 ssl http2;
  server_name domain4.tld;

  root /usr/share/phpmyadmin;
  index index.html index.htm index.php;
}

server {
    listen      80 default_server;
    server_name _;
    root /usr/share/nginx/domain1.tld/public;
    return      444;
}

server {
    listen 80;
    listen [::]:80;
    server_name domain5.tld www.domain5.tld;

    include /etc/nginx/snippets/letsencrypt-acme-challenge.conf;
    include /etc/nginx/snippets/block_agents.conf;
    location / {
        rewrite ^ https://www.domain5.tld$request_uri? permanent;
    }
}

server {
  listen 443 ssl;
  server_name domain5.tld;

  include /etc/nginx/snippets/ssl-params.conf;
  include /etc/nginx/snippets/ssl-domain5.tld.conf;
  include /etc/nginx/snippets/block_agents.conf;
  return 301 https://www.domain5.tld$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.domain5.tld;
    root /usr/share/nginx/domain3.tld/public;
    index index.php index.html index.htm;

    include /etc/nginx/snippets/ssl-params.conf;
    include /etc/nginx/snippets/ssl-domain5.tld.conf;
    include /etc/nginx/snippets/block_agents.conf;
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ /.well-known {
        allow all;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          #root /usr/share/nginx/html;
    }

    location ~ /\. {
      deny  all;
    }
}

upstream php-handler {
    server unix:/run/php/php7.0-fpm.sock;
}

server {
    listen 80; #443 ssl;
    server_name domain6.tld;

    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    root /usr/share/nginx/domain6.tld/public;

    location /.well-known/acme-challenge { }

    client_max_body_size 512M;
    fastcgi_buffers 64 4K;
    gzip off;
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

}

server {
    #listen 443 ssl http2;
    listen 80; # http2;
    server_name domain6.tld;
    root /usr/share/nginx/domain6.tld/public;
    index index.php index.html index.htm;

    #include /etc/nginx/snippets/ssl-params.conf;
    #include /etc/nginx/snippets/ssl-domain2.tld.conf;

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          #root /usr/share/nginx/html;
    }
}

答案1

您尚未将其声明为默认服务器。

listen   80   default_server;

是正确的形式。

http://nginx.org/en/docs/http/server_names.htmlhttp://nginx.org/en/docs/http/ngx_http_core_module.html#listen

相关内容