Once you have installed Kendis Docker and it's up and running, you can follow these steps to configure SSL.

Step 1: Create Directory

Create a directory with name "docker_ssl_proxy" to store the NginX configuration file and the certificate and key

 $ mkdir docker_ssl_proxy

Step 2: Change directory to docker_ssl_proxy

You must be under this directory before executing the following steps (commands).

Step 3.a: Use Signed certificates

If you have certificates you can simply copy following 2 files in the current directory
key.pem
cert.pem

Step 3.b Create the self signed certificates (If need to)

Use OpenSSL to create a self signed certificate, Following command will create a self signed certificate and a private key with a validity of 365 days.

 $ openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365

Step 4: Find your container IP address

4.1: Find your kendis container Id. 

$ docker ps

It will list all the processes that are running and find out your Kendis container id.

4.2 Find IP Address

To find the container IP address from host, you can run the command

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'  <kendis-contrainer-id>

<kendis-container-id>: replace this with the value that you get from Step 4.1

The response of the above command will be an IP address e.g., 

123.12.2.1

Step 5: Create the NginX configuration file

In the same directory, create a configuration file that will proxy all the traffic to your upstream server. The upstream server is the application server running a non SSL connection. The SSL will be using NginX, and all the traffic will be proxied to the host (using your IP address that you got in Step 4.2)

The configuration file, which in this example is called "proxy_ssl.conf," but can have any name as long as it ends in .conf. File must have following contents

 
server {
  listen 443;
  ssl on;
  ssl_certificate /etc/nginx/conf.d/cert.pem;
  ssl_certificate_key /etc/nginx/conf.d/key.pem;
  location / {
  proxy_pass http://123.12.2.1:8080;
 }
}

Only thing you need to replace in this file is IP Addres. We are using example IP 123.12.2.1.

Please note, port shouldn't be changed, it must remain as 8080.

This file simply instructs NginX to listen, with SSL and the correct certs and keys, on port 443 and to proxy all the requests to the host on port 8080

Step 6: Run the docker container

At this point we have all the configuration in place to proxy the traffic, we simply need to run the docker container with following command

$ docker run --name nginx_proxy -d -v pwd:/etc/nginx/conf.d -p 443:443 nginx


NOTE: In case you face issues, try to replace pwd in the command above with the full directory path for "docker_ssl_proxy", where you have config and cert files. 

$docker run --name nginx_proxy -d -v <yourdirectory>:/etc/nginx/conf.d -p 443:443 nginx


All Done. 

Just open browser and hit URL with https.

Did this answer your question?