Skip to content

Instantly share code, notes, and snippets.

@shijij
Created November 14, 2017 12:31
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save shijij/54c9b21f26c08a15a70c182f03cb15b4 to your computer and use it in GitHub Desktop.
Save shijij/54c9b21f26c08a15a70c182f03cb15b4 to your computer and use it in GitHub Desktop.
Nginx ssl reverse proxy with SNI
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name yourdomain
ssl_certificate /etc/ssl/localcerts/yourdomain.crt;
ssl_certificate_key /etc/ssl/localcerts/yourdomain.key;
ssl_ecdh_curve prime256v1;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE+aECDSA+CHACHA20:ECDHE+aRSA+CHACHA20:ECDHE+aECDSA+AESGCM:ECDHE+aRSA+AESGCM:ECDHE+aECDSA+AES256+SHA384:ECDHE+aRSA+AES256+SHA384:ECDHE+aECDSA+AES256+SHA:ECDHE+aRSA+AES256+SHA';
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Fix the “It appears that your reverse proxy set up is broken" error.
proxy_pass https://1.2.3.4;
proxy_read_timeout 60;
proxy_ssl_name $host;
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_session_reuse off;
}
}
@c-l-h
Copy link

c-l-h commented Mar 20, 2019

Thanks for this! - found it after hours of searching and trying to get nginx to reverse proxy to a IIS server that required SNI, interesting that the server_name directive doesnt require a ; in fact it breaks if you add it (i thought it was a typo in your file at first).

I did have to add ssl on; just before the ssl_certificate line though otherwise nginx would try to use the client cert instead of the upsteam cert.

Thanks again

@spuder
Copy link

spuder commented Sep 25, 2019

Thank you, this worked for me.

All I had to do was add these 2 lines to my config

      proxy_ssl_name $host;
      proxy_ssl_server_name on;

I find it is ok to have a ; after server_name, contrary to what c-l-h states. Perhaps newer versions of nginx are more forgiving than the version they are running.

nginx version: nginx/1.15.8
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled

@drwunt
Copy link

drwunt commented Mar 30, 2022

does it works???

https://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_ssl_name
Syntax: proxy_ssl_name name;
Context: stream, server

in your example proxy_ssl_name is used in location

@cnjax
Copy link

cnjax commented Nov 12, 2022

thank you ,it works.

@ManfredBartz
Copy link

Excellent, worked as per your example. :-)
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment