Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/Backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ RUN pip install channels

# Copy the project files into the container
COPY . .

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "backend.wsgi:application"]
4 changes: 1 addition & 3 deletions backend/apps/chat_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ def situation_tuning(self, user, mood):
def audio_send(self, text):
# TTS blob 객체 생성
tts_audio_data = text_to_speach(text)
tts_audio_blob = base64.b64decode(tts_audio_data)
#tts_audio_string = tts_audio_blob.decode('utf-8')
tts_audio_string = base64.b64encode(tts_audio_blob).decode('utf-8')
tts_audio_string = base64.b64encode(tts_audio_data).decode('utf-8')
# TTS blob 전송
self.send(json.dumps({
"event": "question_tts",
Expand Down
3 changes: 0 additions & 3 deletions backend/apps/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# tasks.py
import os

from celery import shared_task
import requests
from dotenv import load_dotenv
Expand All @@ -10,10 +9,8 @@
from openai import OpenAI
import logging
from .models import ChatRoom # ChatRoom 모델을 가져옵니다.

load_dotenv()


OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
client=OpenAI(api_key=OPENAI_API_KEY)
logger = logging.getLogger(__name__)
Expand Down
5 changes: 2 additions & 3 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"52.79.131.251",
]

USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True

# Application definition

Expand All @@ -53,9 +55,6 @@
'drf_yasg',
"django_celery_beat",
"django_celery_results",



'users',
'main',
'apps',
Expand Down
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ boto3==1.34.1
celery==5.3.1
django-celery-beat==2.5.0
django-celery-results==2.5.1
gunicorn==21.2.0
20 changes: 18 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ services:

web:
build: ./backend
restart: always
command: sh -c "dockerize -wait tcp://db:3306 -timeout 1m
&& python manage.py makemigrations users
&& python manage.py makemigrations apps
&& python manage.py makemigrations diary
&& python manage.py migrate
&& python manage.py runserver 0.0.0.0:8000"
&& python manage.py runserver 0.0.0.0:8000
&& gunicorn your_project.wsgi:application -b 0.0.0.0:8000"
volumes:
- .:/app
- ./backend:/backend
ports:
- "8000:8000"
depends_on:
Expand All @@ -48,3 +50,17 @@ services:
- ./backend:/app # 현재 디렉토리를 backend로 변경하여, backend 코드를 컨테이너의 /app으로 마운트
environment:
- DJANGO_SETTINGS_MODULE=config.settings # Django 설정 환경 변수 추가
env_file:
- .env

nginx:
container_name: nginx
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- "8080:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf # 호스트의 nginx 폴더와 컨테이너의 /etc/nginx/conf.d 폴더를 공유
depends_on:
- web
60 changes: 14 additions & 46 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
user nginx; # NGINX 프로세스를 실행할 사용자를 지정합니다.
worker_processes auto; # NGINX 프로세스의 수를 지정합니다.
error_log /var/log/nginx/error.log warn; # 에러 로그 파일의 경로를 지정합니다.
error_log /var/log/nginx/error.log error; # 에러 로그 파일의 경로를 지정합니다.
pid /var/run/nginx.pid; # NGINX 프로세스의 PID 파일의 경로를 지정합니다.

events {
Expand All @@ -10,66 +10,34 @@ events {
http {
include /etc/nginx/mime.types; # MIME 타입 설정 파일을 포함합니다.
default_type application/octet-stream; # 기본 MIME 타입을 설정합니다.

server_tokens off; # NGINX 버전 정보를 응답 헤더에서 제거합니다.
keepalive_timeout 65; # keepalive 타임아웃을 65초로 설정합니다.

upstream channels-backend {
server localhost:8001;
}

#keepalive_timeout 100; # keepalive 타임아웃을 100초로 설정합니다.
error_log /var/log/nginx/error.log error;
access_log /var/log/nginx/access.log;
server {
listen 80; # 80번 포트에서 요청을 수신하도록 설정합니다.
server_name localhost;
location = /favicon.ico { access_log off; log_not_found off; }

# Django 정적 파일 설정
location /static/ {
alias /staticfiles/; # Django의 정적 파일이 저장된 실제 경로로 변경해야 합니다.
expires 30d; # 정적 파일에 대한 캐시 만료 시간을 30일로 설정합니다.
}
#location = /favicon.ico { access_log off; log_not_found off; }

# Django 미디어 파일 설정
location /media/ {
alias /path/to/media/files/; # Django의 미디어 파일이 저장된 실제 경로로 변경해야 합니다.
expires 90d; # 미디어 파일에 대한 캐시 만료 시간을 90일로 설정합니다.
}

# Django 설정 (API페이지)
location /api/ {
proxy_pass http://django:8000; # 여기서 'django'는 Django 서비스의 호스트 이름이나 IP 주소입니다.
# 아래 proxy_set_header 지시문들은 프록시된 요청의 헤더를 설정합니다.
location /api/ {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# Django 설정 (웹소켓)
# location 안에 넣어줘야함
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
# 웹소켓
location /ws/ {
proxy_pass http://web:8000; # Django Channels가 실행 중인 포트로 수정
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_pass http://django:8000; #웹소켓 연결은 이런식으로 진행
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_hide_header Content-Type;
add_header Content-Type $custom_content_type;
}

# gzip 설정
gzip on; # gzip 압축 활성화
gzip_disable "msie6"; # IE6에서 gzip 압축 비활성화
gzip_vary on; # Vary 헤더를 통해 프록시 서버에 압축된 콘텐츠를 캐시하도록 지시
gzip_proxied any; # 모든 프록시된 응답에 대해 gzip 압축 적용
gzip_comp_level 6; # gzip 압축 레벨 설정 (1이 가장 낮고 9가 가장 높음)
gzip_buffers 16 8k; # 압축을 위한 버퍼 크기 설정
gzip_http_version 1.1; # HTTP 버전 1.1 이상에서 gzip 압축을 사용하도록 설정
gzip_min_length 256; # 이 길이 이상의 응답에 대해서만 gzip 압축 적용
# 압축 적용 대상 MIME 타입 설정
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
}
}