【问题标题】:Deny all connections to ports that aren't 443 or 80 over HTTP/HTTPS on NGINX在 NGINX 上通过 HTTP/HTTPS 拒绝所有非 443 或 80 端口的连接
【发布时间】:2020-05-31 18:52:38
【问题描述】:

我在 Nginx 和 Ubuntu 上运行服务器,该站点有一个域。我有一个问题,如果有人导航到 IP 和附加端口 (https://<ip-addr>:<port>),它将加载不应直接访问的服务,可以使用 nmap 找出端口。

我正在尝试向这些类型的连接返回 444。我试过在“服务器”块下添加这些:

if ($host != "domain.tld") {
          return 444;
                   }

    location / {

        return 444;
   }

现在,这些对于拒绝与 IP 的连接并将其限制在域中非常有效,但是如果您执行 ip 和端口,它就可以正常加载。如果其中一些服务没有某种形式的身份验证,那么它们就会暴露给任何人和所有人。

我尝试使用 iptables 来阻止端口,但这也会阻止`https://domain.tld/service,但这需要工作。

服务应该只能通过这个 URL 而不是 IP 和端口访问。

【问题讨论】:

    标签: linux http security nginx webserver


    【解决方案1】:

    试试这个

    server { # Will redirect all http to https
        listen      80 default_server;
        server_name _; # will catch everything
    
        return 301 https://domain.tld$request_uri;
    }
    
    server{ # Will redirect everything that is not "domain.tld" to http://domain.tld
        listen      443 ssl http2;
        server_name _; # will catch everything
    
        ssl_...
    
        return 301 http://domain.tld$request_uri;
    }
    
    server { # Do normal behavior
        listen      443 default_server;
        server_name *.domain.tld; # will catch everything
    
        ssl_...
    
        location / {
            ...
        }
    
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 2017-08-28
      • 2020-05-28
      • 2018-09-17
      • 2019-02-02
      • 1970-01-01
      相关资源
      最近更新 更多