From a89564a1b18140306cb594f59ae6597a575197e1 Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Sun, 26 May 2024 03:42:01 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Chore:=20nginx.conf=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ws 프록시 설정 추가 - 미완성 --- nginx/nginx1.conf | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nginx/nginx1.conf diff --git a/nginx/nginx1.conf b/nginx/nginx1.conf new file mode 100644 index 0000000..7032dfd --- /dev/null +++ b/nginx/nginx1.conf @@ -0,0 +1,34 @@ +server { + listen 80; + server_name api.coatycloset.store; + + location / { + return 301 https://$server_name$request_uri; + } +} + +server { + listen 443 ssl; + server_name api.coatycloset.store; + + ssl_certificate /etc/letsencrypt/live/api.coatycloset.store/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/api.coatycloset.store/privkey.pem; + + client_max_body_size 100M; + + access_log /var/log/nginx/443_access.log; + error_log /var/log/nginx/443_error.log; + + location /api/ { + proxy_pass http://backend: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; + } + + location /ws/ { + proxy_pass http://backend:8001; + + } +} From c87ae789d191f30f87766a304fe6fb987c3d8245 Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Wed, 29 May 2024 01:40:24 +0900 Subject: [PATCH 2/6] =?UTF-8?q?Chore:=20nginx=20=EC=9B=B9=EC=86=8C?= =?UTF-8?q?=EC=BC=93=20=ED=94=84=EB=A1=9D=EC=8B=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - nginx 설정에 웹소켓 서버 프록시 추가 - entrypoint.sh에서 wsgi 실행 명령어 다른 포트로 추가 --- entrypoint.sh | 2 +- nginx/{nginx.conf => nginx-https.conf} | 0 nginx/{nginx1.conf => nginx-ws.conf} | 12 +++++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) rename nginx/{nginx.conf => nginx-https.conf} (100%) rename nginx/{nginx1.conf => nginx-ws.conf} (72%) diff --git a/entrypoint.sh b/entrypoint.sh index 070adcb..34787d0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,7 @@ python manage.py collectstatic --noinput python manage.py shell < tools/create_superuser.py #python manage.py runserver 0.0.0.0:80 -#gunicorn --bind 0.0.0.0:80 config.wsgi:application +gunicorn --bind 0.0.0.0:8001 config.wsgi:application #uvicorn config.asgi:application --workers 4 #gunicorn config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 diff --git a/nginx/nginx.conf b/nginx/nginx-https.conf similarity index 100% rename from nginx/nginx.conf rename to nginx/nginx-https.conf diff --git a/nginx/nginx1.conf b/nginx/nginx-ws.conf similarity index 72% rename from nginx/nginx1.conf rename to nginx/nginx-ws.conf index 7032dfd..5eedad7 100644 --- a/nginx/nginx1.conf +++ b/nginx/nginx-ws.conf @@ -20,7 +20,7 @@ server { error_log /var/log/nginx/443_error.log; location /api/ { - proxy_pass http://backend:8000; + proxy_pass http://backend:8001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -28,7 +28,13 @@ server { } location /ws/ { - proxy_pass http://backend:8001; - + proxy_pass http://backend:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + 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; } } From a9cc6bcdac8ffab3ea7d9e3f38917ba70cb1d5c3 Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Wed, 29 May 2024 16:27:39 +0900 Subject: [PATCH 3/6] =?UTF-8?q?Chore:=20nginx.conf=20proxy=5Fset=5Fheader?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nginx.conf - 웹소켓 프로토콜 업그레이드 처리하기 위해 필요한 헤더 추가 nginx_ws.conf - nginx 웹소켓 따로 프록시 설정한 버전 --- entrypoint.sh | 5 +++-- nginx/{nginx-https.conf => nginx.conf} | 9 ++++++--- nginx/{nginx-ws.conf => nginx_ws.conf} | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) rename nginx/{nginx-https.conf => nginx.conf} (80%) rename nginx/{nginx-ws.conf => nginx_ws.conf} (96%) diff --git a/entrypoint.sh b/entrypoint.sh index 34787d0..83b1dea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,8 +12,9 @@ python manage.py collectstatic --noinput python manage.py shell < tools/create_superuser.py #python manage.py runserver 0.0.0.0:80 -gunicorn --bind 0.0.0.0:8001 config.wsgi:application +#gunicorn --bind 0.0.0.0:8001 config.wsgi:application #uvicorn config.asgi:application --workers 4 #gunicorn config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 -gunicorn config.asgi:application -c tools/gunicorn_prod.conf.py +gunicorn config.wsgi:application -c tools/gunicorn_prod.conf.py +#gunicorn config.asgi:application -c tools/gunicorn_prod_1.conf.py diff --git a/nginx/nginx-https.conf b/nginx/nginx.conf similarity index 80% rename from nginx/nginx-https.conf rename to nginx/nginx.conf index 4225499..fb20fa0 100644 --- a/nginx/nginx-https.conf +++ b/nginx/nginx.conf @@ -25,8 +25,11 @@ server { 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; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; } -# location /static/ { -# alias /backend/static/; -# } } diff --git a/nginx/nginx-ws.conf b/nginx/nginx_ws.conf similarity index 96% rename from nginx/nginx-ws.conf rename to nginx/nginx_ws.conf index 5eedad7..450811f 100644 --- a/nginx/nginx-ws.conf +++ b/nginx/nginx_ws.conf @@ -20,7 +20,7 @@ server { error_log /var/log/nginx/443_error.log; location /api/ { - proxy_pass http://backend:8001; + proxy_pass http://backend: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; @@ -28,7 +28,7 @@ server { } location /ws/ { - proxy_pass http://backend:8000; + proxy_pass http://websocket:8001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; From 1aa69aed73255772dec1a814abd6a809a9fbc481 Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Wed, 29 May 2024 20:53:45 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Chore:=20gunicorn=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EB=AA=85=EB=A0=B9=EC=96=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - wsgi를 asgi로 변경 --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 83b1dea..cb46933 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,5 +16,4 @@ python manage.py shell < tools/create_superuser.py #uvicorn config.asgi:application --workers 4 #gunicorn config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 -gunicorn config.wsgi:application -c tools/gunicorn_prod.conf.py -#gunicorn config.asgi:application -c tools/gunicorn_prod_1.conf.py +gunicorn config.asgi:application -c tools/gunicorn_prod.conf.py From 7a70a9c1d9afcc5c1937880dcd0e03b807f49bd7 Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Wed, 29 May 2024 21:06:33 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Chore:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=84=A4=EC=A0=95=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prod, local에서 GOOGLE_OAUTH2_URL 제거 --- config/settings/local.py | 1 - config/settings/prod.py | 1 - 2 files changed, 2 deletions(-) diff --git a/config/settings/local.py b/config/settings/local.py index 10f3193..bc41851 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -209,7 +209,6 @@ # 커스텀 설정 # TODO FRONT_CONFIRM_URL = env("FRONT_CONFIRM_URL") -GOOGLE_OAUTH2_URL = env("GOOGLE_OAUTH2_URL") CONFIRM_CODE_LENGTH = env("CONFIRM_CODE_LENGTH") EMAIL_CODE_TIMEOUT = env("EMAIL_CODE_TIMEOUT") DJANGO_SUPERUSER_EMAIL = env("DJANGO_SUPERUSER_EMAIL") diff --git a/config/settings/prod.py b/config/settings/prod.py index a758b38..6a634ff 100644 --- a/config/settings/prod.py +++ b/config/settings/prod.py @@ -151,7 +151,6 @@ # 커스텀 설정 # TODO FRONT_CONFIRM_URL = ENV["FRONT_CONFIRM_URL"] -GOOGLE_OAUTH2_URL = ENV["GOOGLE_OAUTH2_URL"] CONFIRM_CODE_LENGTH = ENV["CONFIRM_CODE_LENGTH"] EMAIL_CODE_TIMEOUT = ENV["EMAIL_CODE_TIMEOUT"] DJANGO_SUPERUSER_EMAIL = ENV["DJANGO_SUPERUSER_EMAIL"] From 0b4791f9ea13761105565b6a8a4b23daf81af41e Mon Sep 17 00:00:00 2001 From: yyysolhhh Date: Wed, 29 May 2024 23:06:45 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Feat:=20product=20serializer=EC=97=90?= =?UTF-8?q?=EC=84=9C=20category,=20styles=20=ED=95=84=EB=93=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ProductSerializer - category와 styles를 name으로 처리해야함 - SlugRelatedField로 변경 --- apps/product/serializers.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/product/serializers.py b/apps/product/serializers.py index 91d9aea..9d30556 100644 --- a/apps/product/serializers.py +++ b/apps/product/serializers.py @@ -1,15 +1,10 @@ -# from rest_framework import serializers -# from apps.product.models import Product, ProductImage, ProductCategory, StyleCategory -# from apps.user.models import Account import logging from typing import Any from django.db import transaction from rest_framework import serializers -from rest_framework.fields import ReadOnlyField -from rest_framework.utils.serializer_helpers import ReturnDict -from apps.category.models import Style +from apps.category.models import Category, Style from apps.like.models import Like from apps.product.models import Product, ProductImage, RentalHistory from apps.user.serializers import UserInfoSerializer @@ -32,13 +27,18 @@ class Meta: class ProductSerializer(serializers.ModelSerializer[Product]): - # lender = ReadOnlyField(source="lender.nickname") lender = UserInfoSerializer(read_only=True) - # rental_history = RentalHistorySerializer(many=True, read_only=True) - # images = serializers.SerializerMethodField() images = ProductImageSerializer(many=True, read_only=True) is_liked = serializers.SerializerMethodField() + # product_category = serializers.PrimaryKeyRelatedField(queryset=Category.objects.all(), write_only=True) + # category_name = serializers.ReadOnlyField(source="product_category.name") + product_category = serializers.SlugRelatedField(slug_field="name", queryset=Category.objects.all()) + + # styles = serializers.PrimaryKeyRelatedField(queryset=Style.objects.all(), many=True, write_only=True) + # style_names = serializers.SerializerMethodField(read_only=True) + styles = serializers.SlugRelatedField(many=True, slug_field="name", queryset=Style.objects.all()) + class Meta: model = Product fields = ( @@ -55,7 +55,9 @@ class Meta: "size", "views", "product_category", + # "category_name", "styles", + # "style_names", "status", "amount", "region", @@ -64,10 +66,15 @@ class Meta: "images", "likes", "is_liked", - # "rental_history", ) read_only_fields = ("created_at", "updated_at", "views", "lender", "status", "likes", "is_liked") + # def get_category_name(self, obj: Product) -> str: + # return obj.product_category.name + + # def get_style_names(self, obj: Product) -> list[str]: + # return [style.name for style in obj.styles.all()] + def get_is_liked(self, obj: Product) -> bool: user = self.context["request"].user if user.is_authenticated: