Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#1604 closed defect (invalid)

disable https for UNIX-domain socket path

Reported by: caiguanhao@… Owned by:
Priority: major Milestone:
Component: nginx-module Version: 1.14.x
Keywords: upstream Cc:
uname -a: Linux 4.4.0-105-generic x86_64 GNU/Linux
nginx -V: nginx version: (1.14.0)
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-dynamic-module=/opt/nginx-module-vts-0.1.11 --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

Description

I have a local server binding to a UNIX-domain socket and a remote https server. I want to use https for the remote server. So I use "proxy_pass https:".

upstream backend {
  server unix:///tmp/socket.sock;
  server 12.34.56.78:443 backup;
}

server {
  ...
  proxy_pass https://backend;
}

But error occurred:

[error] 28416#28416: *53094 SSL_do_handshake() failed (SSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol) while SSL handshaking to upstream, client: xxx.xxx.xxx.xxx, server: xxx.com, request: "GET /path HTTP/1.1", upstream: "https://unix:///tmp/socket.sock:/path", host: "xxx.com"

There is no way to define whether to use https in the upstream block. It should disable https connection for UNIX-domain socket path even if we use "proxy_pass https:".

---

Other configs:

Error "The plain HTTP request was sent to HTTPS port"

upstream backend {
  server unix:///tmp/socket.sock;
  server 12.34.56.78:443 backup;
}

server {
  ...
  proxy_pass http://backend;
}

To make it work at the moment, I use plain http:

upstream backend {
  server unix:///tmp/socket.sock;
  server 12.34.56.78 backup;
}

server {
  ...
  proxy_pass http://backend;
}

Change History (1)

comment:1 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: newclosed

The upstream block describes a number of equivalent servers - it is basically a more configurable replacement of a DNS name which resolves to multiple addresses. And the protocol is explicitly configured in the proxy_pass directive.

If you want nginx to use a different protocol when connecting to some servers, you have to configure this on the location level, by using a proxy_pass directive with the different protocol specified. In the particular case of a backup server, an error_page-based fallback solution might be what you need, for example:

location / {
    error_page 502 504 = @fallback;
    proxy_pass http://local;
}

location @fallback {
    proxy_pass https://remote;
}
Note: See TracTickets for help on using tickets.