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: 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 / {

When I access my webapp using 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

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?


To terminate SSL on nginx:

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

listen 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;
  • For my use case I had to copy the ssl files from my docker container onto my host system. – k0pernikus Oct 14 '15 at 9:44

You're close, I think (I'm new to Nginx myself), but your second server block needs a bit more... I have one on my server with this:

listen 443 ssl;
listen [::]:443 ipv6only=on ssl;
charset utf-8;
client_max_body_size 75M;
server_name example.com www.example.com;
ssl_certificate /etc/ssl/certs/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com.key;

Note the following:

  1. The listen directive specifies ssl.
  2. The certificate and certificate key are specified. The cert should be in a place easy to access because it's sent to everyone accessing your site. The key is in a place where only the users needing it can access it.

The ipv6, charset, and client max body are lines I have on my server but aren't needed for what you're doing here. You could name these anything and place them anywhere, so don't get hung up on the exact filename or location if you store yours somewhere else. This is just how I like to do it, and my ls -l output is:

-rw-r--r-- 1 root root 1887 Oct  8 14:16 /etc/ssl/certs/example.com.crt
-rw-r----- 1 root ssl-cert 1704 Oct  8 13:47 /etc/ssl/private/example.com.key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.