@D777Arai

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Docker/NginxでLet's Encrypt(SSL)を設定する方法

解決したいこと

Docker/NginxでLet's Encrypt(SSL)を使いたいです。

以下の構成でLet's Encryptを導入する方法をどなたか詳細にご教示いただけますでしょうか。

docker-compose

version: '3.8'

volumes:
  postgres_volume:

services:
  nginx:
    image: nginx:1.21.3
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/uwsgi_params:/etc/nginx/uwsgi_params
      - ./static:/static
    ports:
      - "8000:8000"
    depends_on: 
      - web
    restart: always

  db:
    build:
      context: .
      dockerfile: Dockerfile2
    volumes:
      - postgres_volume:/var/lib/postgresql/data
      - .:/code
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
    restart: always

  web:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/code
    tty: true
    command: uwsgi --socket :8001 --module config.wsgi
    expose:
      - "8001"
    depends_on:
      - db
    restart: always

Docker File

# Pull base image
FROM python:3.9

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
RUN pip install django==3.1.7
RUN pip install psycopg2==2.8.6
RUN pip install uwsgi==2.0.19.1
RUN pip install whitenoise==5.2.0
RUN pip install django-crispy-forms==1.11.1
RUN pip install django-allauth==0.44.0

#Install Dependencies for Two Factor Authentication
RUN pip install django-two-factor-auth==1.13
RUN pip install django-two-factor-auth[phonenumbers]
RUN pip install django-otp==1.0.2
RUN pip install django-otp-yubikey==1.0.0
RUN pip install twilio==6.54.0
RUN pip install django-formtools==2.3

#Install DB Backup app
RUN pip install django-dbbackup==3.3.0

# Copy project
COPY . /code/

Dockerfile2

# Pull base image
FROM postgres:13.4

# Set work directory
WORKDIR /code

#Update OS
RUN apt update

# Install python and its dependencies
RUN apt install -y python3
RUN apt install -y python3-pip python3-django
RUN apt install python3-psycopg2
RUN pip install uwsgi==2.0.19.1
RUN pip install whitenoise==5.2.0
RUN pip install django-crispy-forms==1.11.1
RUN pip install django-allauth==0.44.0

#Install Dependencies for Two Factor Authentication
RUN pip install django-two-factor-auth==1.13
RUN pip install django-two-factor-auth[phonenumbers]
RUN pip install django-otp==1.0.2
RUN pip install django-otp-yubikey==1.0.0
RUN pip install twilio==6.54.0
RUN pip install django-formtools==2.3

#Install DB Backup app
RUN pip install django-dbbackup==3.3.0

# Copy project
COPY . /code/

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    upstream django {
        server web:8001;
    }

    server {
        listen 8000;
        server_name localhost;
        charset utf-8;

        location /static {
            alias /static;
        }

        location / {
            uwsgi_pass django;
            include /etc/nginx/uwsgi_params;
        }
    }
}
0 likes

1Answer

Comments

Your answer might help someone💌