diff --git a/Deployment/Live/Dockerfile.python b/Deployment/Live/Dockerfile.python new file mode 100644 index 0000000..ba2025a --- /dev/null +++ b/Deployment/Live/Dockerfile.python @@ -0,0 +1,11 @@ +FROM python:3.10 + +COPY clubhaus/requirements.txt /tmp/requirements.txt +RUN pip3 install -r /tmp/requirements.txt +RUN pip3 install gunicorn~=20.1.0 + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +ENV DEBUG_MODE=False +WORKDIR /usr/src/app diff --git a/Deployment/Live/README.md b/Deployment/Live/README.md new file mode 100644 index 0000000..2e1a723 --- /dev/null +++ b/Deployment/Live/README.md @@ -0,0 +1,2 @@ +# Notes +- Use `chown -R www-data:www-data static/` and `chown -R www-data:www-data media/` to give nginx access to the files. Fixes the 403 error when accessing static files \ No newline at end of file diff --git a/Deployment/Live/docker-compose.yml b/Deployment/Live/docker-compose.yml new file mode 100644 index 0000000..99bc019 --- /dev/null +++ b/Deployment/Live/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3" +services: + backend: + container_name: clubhaus_backend + image: icaotix/clubhaus_backend + build: + context: ../../ + dockerfile: Deployment/Live/Dockerfile.python + command: gunicorn clubhaus.wsgi:application --bind 0.0.0.0:12000 + volumes: + - ../../clubhaus:/usr/src/app + environment: + - ALLOWED_HOSTS=clubhaus-schornbach.de + - CSRF_TRUSTED_ORIGINS=https://clubhaus-schornbach.de + - SESSION_COOKIE_SECURE=True + - IP_RATE_LIMIT_TIME=3600 + - DEBUG_MODE=False + - LC_ALL=de_DE.UTF-8 + ports: + - "127.0.0.1:12000:12000" diff --git a/Deployment/Live/nginx.conf b/Deployment/Live/nginx.conf new file mode 100644 index 0000000..215c1fa --- /dev/null +++ b/Deployment/Live/nginx.conf @@ -0,0 +1,42 @@ +upstream clubhaus_website { + server 127.0.0.1:12000; +} + +server { + server_name clubhaus-schornbach.de; + + listen 443 ssl; # managed by Certbot + ssl_certificate /etc/letsencrypt/live/clubhaus-schornbach.de/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/clubhaus-schornbach.de/privkey.pem; # managed by Certbot + include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot + + location / { + proxy_pass http://127.0.0.1:12000; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header HOST $host; + proxy_redirect off; + # allow uploads up to 20 megabytes (like pictures) + client_max_body_size 20M; + } + + # redirect static files to filesystem + location /static/ { + alias /usr/projects/clubhaus/clubhaus/static/; + } + + # redirect media files to filesystem (user uploaded files) + location /media/ { + alias /usr/projects/clubhaus/clubhaus/media/; + } + +} +server { + if ($host = clubhaus-schornbach.de) { + return 301 https://$host$request_uri; + } # managed by Certbot + + server_name clubhaus-schornbach.de; + listen 80; + return 404; # managed by Certbot +}