Setup nginx for django static

This commit is contained in:
IRBorisov 2023-08-08 18:14:30 +03:00
parent 8e2b91402f
commit 2c6038116a
4 changed files with 7 additions and 20 deletions

View File

@ -26,7 +26,6 @@ services:
restart: always restart: always
depends_on: depends_on:
- postgresql-db - postgresql-db
- nginx
build: build:
context: ./rsconcept/backend context: ./rsconcept/backend
env_file: ./rsconcept/backend/.env.dev env_file: ./rsconcept/backend/.env.dev
@ -46,15 +45,3 @@ services:
volumes: volumes:
- postgres_volume:/var/lib/postgresql/data - postgres_volume:/var/lib/postgresql/data
nginx:
restart: always
build:
context: ./nginx
ports:
- 1337:80
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
volumes:
- django_static_volume:/var/www/static
- django_media_volume:/var/www/media

View File

@ -32,7 +32,6 @@ services:
restart: always restart: always
depends_on: depends_on:
- postgresql-db - postgresql-db
- nginx
secrets: secrets:
- db_password - db_password
- django_key - django_key
@ -42,8 +41,8 @@ services:
environment: environment:
SECRET_KEY: /run/secrets/django_key SECRET_KEY: /run/secrets/django_key
DB_PASSWORD: /run/secrets/db_password DB_PASSWORD: /run/secrets/db_password
ports: expose:
- 8000:8000 - 8000
volumes: volumes:
- django_static_volume:/home/app/web/static - django_static_volume:/home/app/web/static
- django_media_volume:/home/app/web/media - django_media_volume:/home/app/web/media
@ -68,7 +67,9 @@ services:
build: build:
context: ./nginx context: ./nginx
ports: ports:
- 1337:80 - 8000:80
depends_on:
- backend
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
volumes: volumes:
- django_static_volume:/var/www/static - django_static_volume:/var/www/static

View File

@ -1,12 +1,12 @@
upstream innerdjango { upstream innerdjango {
server back:8000; server backend:8000;
# `backend` is the service's name in docker-compose.yml, # `backend` is the service's name in docker-compose.yml,
# The `innerdjango` is the name of upstream, used by nginx below. # The `innerdjango` is the name of upstream, used by nginx below.
} }
server { server {
listen 80; listen 80;
server_name localhost dev.concept.ru www.dev.concept.ru portal.acconcept.ru www.portal.acconcept.ru; server_name dev.concept.ru www.dev.concept.ru portal.acconcept.ru www.portal.acconcept.ru;
location / { location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host; proxy_set_header Host $host;

View File

@ -13,7 +13,6 @@ fi
cd $APP_HOME cd $APP_HOME
python $APP_HOME/manage.py collectstatic --noinput --clear python $APP_HOME/manage.py collectstatic --noinput --clear
python $APP_HOME/manage.py makemigrations
python $APP_HOME/manage.py migrate python $APP_HOME/manage.py migrate
# Execute given input command # Execute given input command