Ubuntu服务器,拒绝域重定向到IP

时间:2020-05-18 13:27:00

标签: ubuntu nginx server dns ip

除了我自己的域外,我如何拒绝/阻止所有其他试图使用服务器IP的域?我有一台具有他人使用的IP的ubuntu服务器(正在出租该服务器)。他有自己的域名重定向到我的IP。我正在使用nginx,这是我的nginx / sites-available / default文件(我使用的是default,因为我将永远只有一个站点):

server {
  listen 80;
  return 301 https://$host$request_uri;
}

server {
   listen 443;
   server_name example.com www.example.com;

   ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
   ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
   ssl on;

   ssl_session_cache builtin:1000 shared:SSL:10m;

   access_log /var/log/nginx/access.log;

   location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_pass http://localhost:8080;
      proxy_read_timeout 90;
      proxy_redirect http://localhost:8080 https://example.com;
   }

   include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}

我想我可以通过以下方式将它们重定向到我的域:

  if ($host != "example.com") {
     return 301 https://example.com;
  }

但我宁愿现在完全允许他们访问。

顺便说一句,如果与任何事情有关,我正在使用tomcat来运行我的应用程序。

0 个答案:

没有答案