๐ daphne์ postgres, nginx๋ฅผ ์ด์ฉํด์ ๋ฐฐํฌ๋ฅผ ์งํํ๋ ค๊ณ ํ๋ค.
- root passwd ์ด๊ธฐํ
sudo passwd root- root ์ ์ ํ ๊ณ์ ๋น๋ฐ๋ฒํธ ์ด๊ธฐํ
su root
passwd ubuntu- ํค ์์ด ๋ก๊ทธ์ธ
sudo vi /etc/ssh/sshd_config
PasswordAuthentication no- adduser useradd ์ฐจ์ด
adduser : ์คํ ์ ๊ณ์ ์ ๋ณด๋ฅผ ์๋์ผ๋ก ์์ฑ
useradd : ๊ณ์ ๋ง ์์ฑํ๋ฉฐ ๊ธฐํ ๊ณ์ ์ ๋ณด๋ ์๋์ผ๋ก ์์ฑ ๋ฐ ์ค์ - ๋ณด์์ ์ํ ๋ค๋ฅธ ๊ณ์ ์์ฑ
adduser django
sudo passwd django
sudo visudo
django ALL=(ALL) ALL ์ถ๊ฐ- ํคํ์ด ๋ก๊ทธ์ธ์ ์ค์
sudo cp /home/ec2-user/.ssh/ /home/django/.ssh/
sudo chown -R django:django /home/djanog/.ssh- hostname ์ค์
hostnamectl set-hostname django_aws
sudo reboot ๋ค์ ์์ํด์ผ ์ ์ฉ๋จ!
version: '3.8' services: backend: container_name: backend build: ./backend/ entrypoint: sh -c "python manage.py collectstatic --no-input && python manage.py makemigrations && python manage.py migrate && daphne Togeduck.asgi:application -b 0.0.0.0 -p 8000" ports: - 80:8000 volumes: - ./backend/django/:/app/ - /etc/localtime:/etc/localtime:ro # host์ timezone ์ค์ ์ ์ปจํ ์ด๋์ ์ ์ฉํฉ๋๋ค. # ro ์ ์ฝ๊ธฐ ์ ์ฉ(read only) ์์ฑ์ผ๋ก ๋ณผ๋ฅจ์ ์ค์ ํ๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. restart: always
version: '3.8' volumes: postgres: {} django_media: {} django_static: {} services: postgres: container_name: postgres image: postgres:14.5 volumes: - postgres:/var/lib/postgresql/data/ environment: - POSTGRES_USER=user - POSTGRES_PASSWORD=P@ssw0rd - POSTGRES_DB=django restart: always backend: container_name: backend build: ./backend/ entrypoint: sh -c "python manage.py collectstatic --no-input && python manage.py migrate && daphne Togeduck.asgi:application -b 0.0.0.0 -p 8000" volumes: - ./backend/django/:/app/ - /etc/localtime:/etc/localtime:ro - django_media:/app/media/ # nginx์์ media๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก volume์ ์ง์ ํด์ค๋๋ค. - django_static:/app/static/ # nginx์์ static์ ์ฌ์ฉํ ์ ์๋๋ก volume์ ์ง์ ํด์ค๋๋ค. environment: # django์์ ์ฌ์ฉํ ์ค์ ๋ค์ ์ง์ ํด์ค๋๋ค. - DEBUG=1 - POSTGRES_DB=django - POSTGRES_USER=user - POSTGRES_PASSWORD=P@ssw0rd - POSTGRES_HOST=postgres - POSTGRES_PORT=5432 depends_on: - postgres restart: always nginx: container_name : nginx image: nginx:1.23.2 ports: - "80:80" - "443:443" volumes: - ./nginx/default.conf:/etc/nginx/conf.d/default.conf - django_media:/media/ # django์ media๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก volume์ ์ง์ ํด์ค๋๋ค. - django_static:/static/ # django์ static ์ฌ์ฉํ ์ ์๋๋ก volume์ ์ง์ ํด์ค๋๋ค. depends_on: - backend restart: always
# python 3.10.8๋ฒ์ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํด ๋น๋ FROM python:3.8.10 # .pyc ํ์ผ์ ์์ฑํ์ง ์๋๋ก ์ค์ ํฉ๋๋ค. ENV PYTHONDONTWRITEBYTECODE 1 # ํ์ด์ฌ ๋ก๊ทธ๊ฐ ๋ฒํผ๋ง ์์ด ์ฆ๊ฐ์ ์ผ๋ก ์ถ๋ ฅํ๋๋ก ์ค์ ํฉ๋๋ค. ENV PYTHONUNBUFFERED 1 # /app/ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค. RUN mkdir /app/ # /app/ ๊ฒฝ๋ก๋ฅผ ์์ ๋๋ ํ ๋ฆฌ๋ก ์ค์ ํฉ๋๋ค. WORKDIR /app/ # requirments.txt๋ฅผ ์์ ๋๋ ํ ๋ฆฌ(/app/) ๊ฒฝ๋ก๋ก ๋ณต์ฌํฉ๋๋ค. COPY ./django/requirements.txt . # ํ๋ก์ ํธ ์คํ์ ํ์ํ ํจํค์ง๋ค์ ์ค์นํฉ๋๋ค. RUN pip install --no-cache-dir -r requirements.txt # daphne์ ์ฌ์ฉํ๊ธฐ ์ํ ํจํค์ง๋ฅผ ์ค์นํฉ๋๋ค. + postgres RUN pip install Daphne psycopg2
ํ์๋ค์ ๋์์ฃผ๊ณ ์๋ฌ๋ฅผ ํด๊ฒฐํ๊ณ ํ๋๋์ ์๊ฐ์ด ๋ค ๊ฐ๋ฒ๋ ธ๋ค. ๋ฐฐํฌ ํ์๋์ ๋ฌธ์ ๊ฐ ๋๋ฌด ๋ง์ด ์ผ์ด๋ฌ๊ณ ์น์์ผ์ด ์ ๋๋ก ์๋ํ์ง ์๋ ๋ฌธ์ ๋ ๋ฐ์ํ๋ค.
์๋ฌ ๊ด๋ จํ ๊ฒ๋ค์ ๋ด์ผ ๋ค์ ์ ๋ฆฌํด์ผ๊ฒ ๋ค.