thayronarrais/docker-laravel-postgres-nginx

letsencrypt - certbot

Closed this issue · 1 comments

how to add letsencrypt certbot?

If you are trying to create an HTTPS dockerize Nginx container you need to do similar to the following:

In your docker-compose.yml file you will need to create a Dockerfile build for the container.

services:
  nginx:
    build:
      context: .
      dockerfile: nginx.dockerfile

Then continue creating the defined file nginx.dockerfile

FROM nginx:latest
RUN apt-get update
RUN apt-get install -y openssl
RUN mkdir -p /etc/nginx/certs/self-signed/

# Note Describes the command below: Replace values {VALUES} with own
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/self-signed/ssldocker.test.key -out /etc/nginx/certs/self-signed/ssldocker.test.crt -subj "/C={YOUR_COUNTRY}/ST="{YOUR_STATE}"/L={YOUR_CITY}/O=Development/OU=Dev/CN=ssldocker.test"
RUN openssl dhparam -out /etc/nginx/certs/dhparam.pem 2048

Then add server block in Nginx conf file:

server {
    listen 443 ssl;
    index index.html;
    server_name ssldocker.test;

    root /var/www/html;

    location / {
        try_files $uri $uri/ /404.html;
    }

    ssl_certificate /etc/nginx/certs/self-signed/ssldocker.test.crt;
    ssl_certificate_key /etc/nginx/certs/self-signed/ssldocker.test.key;
    ssl_dhparam /etc/nginx/certs/dhparam.pem;
}

Hopes this helps or at least gets you in a path to better find an answer to your question!
~😀💻