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

Соединение Nginx с вышестоящим Apache: сбой повторного согласования

Я настраиваю новый сервер Nginx, который будет использоваться как обратный прокси. У нас есть старый сервер Debian с запущенным Apache. На этом сервере apache есть сайт с доступом только по протоколу HTTPS, который я хочу спрятать за прокси.

Подключение прокси-сервера к вышестоящему Apache должно осуществляться через HTTPS (серверы находятся в разных местах, и apache разрешает доступ только по HTTPS).

Моя проблема в том, что соединение Nginx с Apache не работает. Нормальное соединение браузера с апстримом по HTTPS работает без проблем. Подключение с того же прокси к восходящему потоку Nginx работает. Когда Nginx пытается подключиться к восходящему соединению Apache, происходит сбой с Рукопожатие повторного согласования не удалось

В журнале прокси Nginx (уровень отладки) говорится только:

2016/04/07 15:51:08 [error] 5855#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 94.113.97.9, server: procrastination.com, request: "GET / HTTP/1.1", upstream: "https://77.240.191.234:443/", host: "procrastination.com"

Журнал из вышестоящего Apache:

[Thu Apr 07 15:36:48 2016] [info] Initial (No.1) HTTPS request received for child 35 (server procrastination.com:443)
[Thu Apr 07 15:36:48 2016] [debug] ssl_engine_kernel.c(421): [client 83.167.254.21] Reconfigured cipher suite will force renegotiation
[Thu Apr 07 15:36:48 2016] [info] [client 83.167.254.21] Requesting connection re-negotiation
[Thu Apr 07 15:36:48 2016] [debug] ssl_engine_kernel.c(764): [client 83.167.254.21] Performing full renegotiation: complete handshake protocol (client does support secure renegotiation)
[Thu Apr 07 15:36:48 2016] [info] [client 83.167.254.21] Awaiting re-negotiation handshake
[Thu Apr 07 15:36:58 2016] [error] [client 83.167.254.21] Re-negotiation handshake failed: Not accepted by client!?

Конфигурация моего сайта Nginx на прокси:

server {
  listen 80;
  listen 443 ssl;

  server_name procrastination.com *.procrastination.com;

  ###
  # SSL
  ###
  ssl  on;
  ssl_certificate         /etc/ssl/localcerts/procrastination.com/fullchain.pem;
  ssl_certificate_key     /etc/ssl/localcerts/procrastination.com/privkey.pem;

  ##
  # Logging Settings
  ##
  access_log /var/log/nginx/procrastination_proxy-access.log;
  error_log /var/log/nginx/procrastination_proxy-error.log debug;


  include /etc/nginx/snippets/common;
  include /etc/nginx/snippets/proxy_params;

  location / {
    proxy_pass https://brigita_https;
    proxy_ssl_name $host;
  }
}

Связанная с SSL часть nginx.conf на прокси:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

Конфигурация сайта Apache в восходящем направлении:

<VirtualHost 77.240.191.234:80>
  ServerName procrastination.com
  ServerAlias *.procrastination.com
  DocumentRoot /var/www/procrastination-production/build/current/www
  php_value newrelic.appname /var/www/procrastination-production/build/current/www

  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]

</VirtualHost>


<VirtualHost 77.240.191.234:443>
  ServerName procrastination.com
  ServerAlias *.procrastination.com
  DocumentRoot /var/www/procrastination-production/build/current/www
  php_value newrelic.appname /var/www/procrastination-production/build/current/www

  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/ssl_procrastination_com.crt
  SSLCertificateKeyFile /etc/apache2/ssl/ssl_procrastination_com.key

  RewriteCond %{HTTP_HOST} !^www\..*$
  RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L]

</VirtualHost>

Другие значения конфигурации Apache по умолчанию.

Есть идеи, что может быть причиной или где искать дополнительные диагностические данные?

Решено!

Проблема была в SNI на восходящем потоке Apache. Nginx не передал правильные параметры, и Apache отправил ему неправильный сертификат.

Вам нужно установить proxy_ssl_server_name on в конфиге Nginx.

Просто измените:

  location / {
    proxy_pass https://brigita_https;
    proxy_ssl_name $host;
  }

кому:

  location / {
    proxy_pass https://brigita_https;
    proxy_ssl_name $host;
    proxy_ssl_server_name on;
  }