Назад | Перейти на главную страницу

nginx: браузер переписывает http-запрос на https, когда он не нужен

Итак, у меня есть конфигурация nginx, которая выглядит так:

## 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;
  }
}

Намерение состоит в том, чтобы направить HTTP-трафик с порта 80 на https (443). Работает как чемпион. Проблема в том, что мой запрос на порт 9080 заставляет мой браузер переключаться на https, а затем терпит неудачу (поскольку я не использую ssl на 9080 и не хочу).

В Safari или Chrome: http://me.example.com:9080/index.html -> https://me.example.com:9080/index.html Не удается установить безопасное соединение.

С 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

Это проблема браузера? Что я могу сделать, чтобы сделать браузер счастливым?

ОБНОВИТЬ

В Chrome вы можете удалить сайт из HSTS, перейдя по этому URL:

хром: // net-internals / # hsts

ч / т до этот сайт также есть инструкции для других браузеров.

Я предполагаю, что вы отправляете HTTP Strict-Transport-Security (HSTS) заголовок из блока сервера HTTPS.

Заголовок HSTS предназначен для привязки к имени домена, от которого он был получен. Затем он известен как хост HSTS агентом пользователя (UA) и хранится в его кэше в течение max-age секунд.

В течение этого времени дальнейшие HTTP-запросы к домену или действующему поддомену, если это сообщается includeSubDomains директива, пройдет специальную обработку, описанную RFC 6797 раздел 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")).

Это означает, что если вы пытаетесь отправить HTTP-запрос на известный хост HSTS с совпадающим доменным именем (Раздел 8.2 для деталей), то до тех пор, пока не истек срок действия записи хоста HSTS в кэше UA, HTTP-трафик будет прозрачно переключаться на HTTPS:

  • на порту 443, если порт HTTP был 80 (явно или неявно) в целевом URI
  • на тот же порт в противном случае