1) Pull nginx image
docker image pull nginx
2) Create nginx container
docker container run -d -p 443:443 --name mynginx nginx
3) Enter the container
docker container exec -it mynginx bash
4) Create the private key and certificate
mkdir /etc/nginx/ssl
private key
openssl genrsa -out /etc/nginx/ssl/server.key 2048
Certificate Signing Request (CSR)
you can skip through by pressing the Enter key for each prompt
openssl req -new -key /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.csr
SSL server certificate (CRT)
openssl x509 -days 3650 -req -signkey /etc/nginx/ssl/server.key -in /etc/nginx/ssl/server.csr -out /etc/nginx/ssl/server.crt
5) Edit the Nginx configuration file
vi /etc/nginx/conf.d/ssl.conf
server {
listen 443 default ssl;
root /usr/share/nginx/html;
index index.html index.htm;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
}
6) Reload the Nginx configuration
service nginx reload
7) Access the following URL
https://container-IP/
Top comments (0)