diff --git a/core/settings.py b/core/settings.py index 7fb9d8f..f141315 100644 --- a/core/settings.py +++ b/core/settings.py @@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/5.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.2/ref/settings/ """ - +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -116,6 +116,11 @@ USE_TZ = True # https://docs.djangoproject.com/en/5.2/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') + +MEDIA_URL = 'media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + # Default primary key field type # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..101fdb6 --- /dev/null +++ b/default.conf @@ -0,0 +1,18 @@ +server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://web:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + location /static/ { + alias /app/staticfiles/; + } + + location /media/ { + alias /app/media/; + } +} \ No newline at end of file diff --git a/docker-compose copy.yml b/docker-compose copy.yml index 198934e..132c138 100644 --- a/docker-compose copy.yml +++ b/docker-compose copy.yml @@ -1,11 +1,21 @@ -version: '3.8' - services: web: build: . volumes: - .:/app + # Больше не открываем порт 8080 наружу для Django, + # теперь его будет "прикрывать" Nginx + expose: + - "8000" + command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --workers 3 + + nginx: + image: nginx:latest + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./staticfiles:/app/staticfiles + - ./media:/app/media ports: - - "8080:8000" - environment: - - DEBUG=1 \ No newline at end of file + - "8080:80" + depends_on: + - web \ No newline at end of file