Nginx – How to setup SSL reverse proxy using nginx

nginxreverse-proxysslssl-certificate

Related to my question about how to setup a reverse proxy using nginx, I am now stuck when setting up one which additionally requires a SSL connection.

I have docker container which provides the mapped SSL-port 4430 to my host-stystem. The webserver is using a self-signed certificate.

In my /etc/hosts file, I have defined:

127.0.0.1 app.local

And my nginx server config looks like:

server {
    listen 80;
    server_name app.local;
    location / {
        return https://$host$request_uri;
    }
}

server {
    listen 443;
    server_name app.local;
    location / {
        proxy_pass https://127.0.0.1:4430;
    }
}

When I access my webapp using https://127.0.0.1::4430 it works fine. I get a warning about the certificate the first time though, which I then have to allow.

Yet when connecting to it via either http://app.local orhttps://app.local , my browser shows a:

SSL connection error
ERR_SSL_PROTOCOL_ERROR

I also was expecting for the certificate warning to appear which I then could allow.

How to get the reverse proxy working when using SSL with nginx?

Best Answer

To terminate SSL on nginx:

a) The server section needs to specify port and 'ssl'

listen 192.168.2.26:443 ssl;

b) The server block then also specifies certs and ssl params

ssl_certificate      new-cert.cer;
ssl_certificate_key  new-cert.key;

ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
Related Topic