π λλμ΄ ν΄λλ€ μ§μ§ γ γ λ무 νλ€μμ§λ§ uvicornμΌλ‘ λ°°ν¬νμ¬ νλ‘μΈμ€λ₯Ό νλλ§ μ°λκ² λ무 λ© μμ΄λ³΄μ΄κ³ λ§μμ μλ€μ΄ κ³μ μλνμ¬ μ±κ³΅νλ€.
κ³μ μλνλ©΄μ nginx docker μ€μ λ€κ³Ό μλ λ°©μμ λν΄ λ§μ΄ μκ²λμκ³ μμ κ°λ λΆκ³ λ무 ν볡νλ€ γ γ docker compose
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 networks: carrot: ipv4_address: 192.168.16.2 redis: image: redis ports: - "6379:6379" networks: carrot: ipv4_address: 192.168.16.3 backend: container_name: backend build: ./backend/ command: sh -c "python manage.py collectstatic --no-input && python manage.py migrate && daphne -b 0.0.0.0 -p 8000 Togeduck.asgi:application" volumes: - ./backend/django/:/app/ - /etc/localtime:/etc/localtime:ro - django_media:/app/media/ - django_static:/app/static/ environment: # djangoμμ μ¬μ©ν μ€μ λ€μ μ§μ ν΄μ€λλ€. - DEBUG=1 - POSTGRES_DB=django - POSTGRES_USER=user - POSTGRES_PASSWORD=P@ssw0rd - POSTGRES_HOST=postgres - POSTGRES_PORT=5432 depends_on: - postgres - redis links: - redis restart: always hostname: backend ports: - 8000:8000 networks: carrot: ipv4_address: 192.168.16.4 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_static:/static/ depends_on: - backend restart: always networks: carrot: ipv4_address: 192.168.16.6 networks: carrot: driver: bridge ipam: driver: default config: - subnet: 192.168.16.0/16
nginx
upstream backend { server backend:8000; # backend 8000 μΌλ‘ μ²μμ μμ λ°κΎΈμ΄μ€ } server { listen 80; server_name www.carrotww.shop; # λλ©μΈμΌλ‘ λ€μ΄μ€λ μμ²μ μ²λ¦¬ location / { proxy_pass http://backend; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; client_max_body_size 0; } location /static/ { alias /static/; } location /media/ { alias /media/; } location /ws { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://backend; } } server { listen 80; server_name carrotww.shop; # wwwκ° μλ urlλ‘ μμ² νμ λ return 301 http://www.carrotww.shop$request_uri; # wwwλ₯Ό λΆμΈ urlλ‘ redirection }
Docker file
# 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 --upgrade pip RUN pip install --no-cache-dir -r requirements.txt # for django-crontab RUN chmod -R 777 /app #κΆν μ€μ RUN apt-get update RUN apt-get install -y cron && touch /score.log #crontab μ€μΉ λ° λ‘κ·ΈνμΌ μμ± # daphne μ€μΉ RUN pip install daphne psycopg2
π daphneμ λν μ λ³΄κ° λ§μ΄ λΆμ‘±νμ¬ μ΄κ²μ κ² λ€ ν΄λ³΄λ©΄μ μλν κ²°κ³Όκ° μ±κ³΅μ΄μ¬μ λ€νμ΄λ€. λν νν°λμ΄ μλλ€κ³ νλκ±Έ λ΄κ° ν΄λ΄λκΉ κΈ°λΆμ΄ λ무 μ’λ€ γ γ γ
νλ‘μ νΈμ λ€μ΄μ¨ νΌλλ°±μ΄λ κΈ°λ₯ μμ μ νλ©° ννν λ―Έλ ¨μ λͺ»λ²λ¦¬κ³ λͺλ²μ© μΌμ£ΌμΌλμ μλν΄λ³΄κ³ μ±κ³΅ν΄μ λμ± κΈ°μκ² κ°λ€.
μ΄μ λ°°ν¬λ μ§μ§ λμ...