This is based on the marvellous blog posting by Oliver Zampieri.
This howto is written to create a self signed SSL NginX proxy on MacOS to
- Expose proxy at local host port
5001
- Connect the port
5001
to port443
inside Docker - Proxy the port
443
to port5000
on the host computer
This means that:
- Your application should be listening on
http://0.0.0.0:5000
- Your application will be accessible at https://myhost.local:5001
We will use myhost.local
as the hostname. You can change this.
$ mkdir docker-ssl-proxy
$ cd docker-ssl-proxy
$ openssl req -subj '/CN=myhost.local' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365
Add this line in your /etc/hosts
file
127.0.0.1 myhost.local
Create proxy_ssl.conf
file. This will work out of the box on MacOS and connect to your local application on port 5000
.
server {
listen 443 ssl;
ssl_certificate /etc/nginx/conf.d/cert.pem;
ssl_certificate_key /etc/nginx/conf.d/key.pem;
location / {
proxy_pass http://docker.for.mac.localhost:5000;
}
}
$ docker run --name nginx-proxy -d -v ${PWD}:/etc/nginx/conf.d -p 5001:443 nginx
docker stop nginx-proxy
docker start nginx-proxy
docker kill nginx-proxy
docker rm nginx_proxy