nginx: navegador reescrevendo requisição http para https quando não queria

3

Então eu tenho uma configuração nginx que se parece com isso:

## Redirects all HTTP traffic to the HTTPS host
server {
  listen *:80;
  server_name me.example.com;
  server_tokens off;
  return 301 https://me.example.com:443$request_uri;
  access_log  /var/log/nginx/access.log;
  error_log   /var/log/nginx/error.log;
}

server {
  listen *:443 ssl;
  ...
}

server {
  listen *:9080;
  location / {
    root /var/www;
    index index.html index.htm;
  }
}

A intenção é direcionar o tráfego http na porta 80 para https (443). Funciona como um campeão. O problema é que minha solicitação para a porta 9080 está fazendo com que meu navegador mude para https e, em seguida, falhe (já que não estou usando o ssl no 9080, nem quero).

No Safari ou no Chrome: http://me.example.com:9080/index.html -> https://me.example.com:9080/index.html Não é possível estabelecer uma conexão segura.

Com CURL:

curl -v http://me.example.com:9080/index.html
* Hostname was NOT found in DNS cache
*   Trying x.x.x.x...
* Connected to me.example.com (x.x.x.x) port 9080 (#0)
> GET /index.html HTTP/1.1
> User-Agent: curl/7.37.1
> Host: me.example.com:9080
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server nginx/1.4.4 is not blacklisted
< Server: nginx/1.4.4
< Date: Thu, 09 Apr 2015 18:32:02 GMT
< Content-Type: text/html
< Content-Length: 157
< Last-Modified: Thu, 09 Apr 2015 18:19:42 GMT
< Connection: keep-alive
< ETag: "5526c2be-9d"
< Accept-Ranges: bytes
< 
<html>
<head>
<title>Test Server</title>
</head>
<body>
<h3>Welcome to the Test Server!"</h3>
</body>
</html>
* Connection #0 to host me.example.com left intact

Isso é um problema no navegador? Há algo que eu possa fazer para deixar o navegador feliz?

UPDATE

No Chrome, você pode remover um site do HSTS navegando até este URL:

chrome: // net-internals / # hsts

h / t para este site que também contém instruções para outros navegadores.

    
por Ben Flynn 09.04.2015 / 20:46

1 resposta

5

Suponho que você está enviando um cabeçalho HTTP Strict-Transport-Security (HSTS) do bloco do servidor HTTPS.

O objetivo do cabeçalho da HSTS é vincular-se ao nome de domínio do qual foi recebido. É então conhecido como um host HSTS pelo User-Agent (UA) e mantido em seu cache por max-age segundos.

Durante esse tempo, mais solicitações HTTP para o domínio, ou um subdomínio válido, se informado pela diretiva includeSubDomains , passarão por um processamento especial descrito por RFC 6797 seção 8.3 :

      The UA MUST replace the URI scheme with "https" [RFC2818], and

      if the URI contains an explicit port component of "80", then
      the UA MUST convert the port component to be "443", or

      if the URI contains an explicit port component that is not
      equal to "80", the port component value MUST be preserved;
      otherwise,

      if the URI does not contain an explicit port component, the UA
      MUST NOT add one.

     NOTE:  These steps ensure that the HSTS Policy applies to HTTP
            over any TCP port of an HSTS Host.

NOTE:  In the case where an explicit port is provided (and to a
       lesser extent with subdomains), it is reasonably likely that
       there is actually an HTTP (i.e., non-secure) server running on
       the specified port and that an HTTPS request will thus fail
       (see item 6 in Appendix A ("Design Decision Notes")).

Isso significa que, se você estiver tentando enviar uma solicitação HTTP para um host HSTS conhecido com um nome de domínio correspondente ( seção 8.2 para os detalhes) e enquanto a entrada do host HSTS no cache do UA não tiver expirado, o tráfego HTTP será alternado de forma transparente para o HTTPS:

  • na porta 443 se a porta HTTP fosse 80 (explícita ou implicitamente) no URI de destino
  • na mesma porta caso contrário
por 10.04.2015 / 00:11

Tags