Nginx config

Fixes #152 (hopefully???)
Fixes #130
Fixes #125
This commit is contained in:
Mouse Reeve 2020-05-17 20:20:51 -07:00
parent 845401bd62
commit dbabeab470
5 changed files with 48 additions and 11 deletions

View file

@ -1,9 +1,10 @@
FROM python:3 FROM python:3
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
RUN mkdir /app RUN mkdir /app
RUN mkdir /app/static
RUN mkdir /app/images
WORKDIR /app WORKDIR /app
COPY requirements.txt /app/ COPY requirements.txt /app/
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY ./fedireads /app COPY ./fedireads /app
COPY ./fr_celery /app COPY ./fr_celery /app
EXPOSE 5555

View file

@ -1,6 +1,17 @@
version: '3' version: '3'
services: services:
nginx:
build: ./nginx
ports:
- 1333:80
depends_on:
- web
networks:
- main
volumes:
- static_volume:/app/static
- media_volume:/app/images
db: db:
image: postgres image: postgres
env_file: .env env_file: .env
@ -13,13 +24,15 @@ services:
command: python manage.py runserver 0.0.0.0:8000 command: python manage.py runserver 0.0.0.0:8000
volumes: volumes:
- .:/app - .:/app
ports: - static_volume:/app/static
- "8000:8000" - media_volume:/app/images
depends_on: depends_on:
- db - db
- celery_worker - celery_worker
networks: networks:
- main - main
expose:
- 8000
redis: redis:
image: redis image: redis
env_file: .env env_file: .env
@ -40,14 +53,9 @@ services:
- db - db
- redis - redis
restart: on-failure restart: on-failure
flower:
image: mher/flower
command: ["flower", "--broker=redis://redis:6379/0", "--port=5555"]
env_file: .env
ports:
- "5555:5555"
restart: on-failure
volumes: volumes:
pgdata: pgdata:
static_volume:
media_volume:
networks: networks:
main: main:

View file

@ -138,6 +138,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/ # https://docs.djangoproject.com/en/2.0/howto/static-files/
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, env('STATIC_ROOT', 'static'))
MEDIA_URL = '/images/' MEDIA_URL = '/images/'
MEDIA_ROOT = os.path.join(BASE_DIR, env('MEDIA_ROOT', 'images/')) MEDIA_ROOT = os.path.join(BASE_DIR, env('MEDIA_ROOT', 'images'))

4
nginx/Dockerfile Normal file
View file

@ -0,0 +1,4 @@
FROM nginx:1.17.4-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

22
nginx/nginx.conf Normal file
View file

@ -0,0 +1,22 @@
upstream web {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass http://web;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /images/ {
alias /app/images/;
}
location /static/ {
alias /app/static/;
}
}