Forem

Norman
Norman

Posted on

2

Hosting index.html with HTTPS using Docker and Nginx

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;
}
Enter fullscreen mode Exit fullscreen mode

6) Reload the Nginx configuration
service nginx reload

7) Access the following URL
https://container-IP/

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)