@lizzie
To run NGINX through Docker with HTTPS, you can follow these steps:
- Create a self-signed SSL certificate and key. You can use a tool like OpenSSL to generate a self-signed SSL certificate and key file.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /path/to/ssl.key -out /path/to/ssl.crt
- Create a Dockerfile for NGINX that copies the SSL certificate and key files into the container.
FROM nginx
COPY /path/to/ssl.crt /etc/ssl/certs/nginx.crt
COPY /path/to/ssl.key /etc/ssl/private/nginx.key
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 443
- Create an NGINX configuration file (nginx.conf) that configures NGINX to use the SSL certificate and key files.
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/ssl/certs/nginx.crt;
ssl_certificate_key /etc/ssl/private/nginx.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
- Build the NGINX Docker image using the Dockerfile and nginx.conf file.
docker build -t my-nginx .
- Run the NGINX Docker container with port 443 mapped to the host machine. This will expose NGINX running with HTTPS.
docker run -d -p 443:443 my-nginx
Now NGINX should be running through Docker with HTTPS enabled. You can access the NGINX server using a web browser and HTTPS protocol.