Allow Django to serve static files directly

This commit is contained in:
Gilles Roudière
2021-04-21 14:39:18 +02:00
parent ceee35c238
commit bde4ac975d
4 changed files with 19 additions and 9 deletions

View File

@@ -36,8 +36,8 @@ services:
depends_on:
- database
- keycloak
volumes:
- statics:/var/www/showreel.godotengine.org/static/
#volumes:
#- statics:/var/www/showreel.godotengine.org/static/
secrets:
- gdshowreel_django_db_password
- gdshowreel_django_secret
@@ -47,7 +47,7 @@ services:
nginx:
build: nginx
volumes:
- statics:/var/www/showreel.godotengine.org/static/
#- statics:/var/www/showreel.godotengine.org/static/
- ./certificates:/etc/nginx/ssl/ # WARNING: in production, change to real certificates storage dir
ports:
- "80:80"
@@ -67,5 +67,6 @@ secrets:
gdshowreel_oidc_rp_client_secret:
file: ./secrets/gdshowreel_oidc_rp_client_secret.txt
volumes:
statics:
# The following lines and the corresponding volumes mounts can be uncommented for allowing the nginx server to serve the static files (if the Django app doesn't do it)
#volumes:
# statics:

View File

@@ -129,6 +129,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
SERVE_STATICS = True
STATIC_ROOT = os.environ.get('DJANGO_STATIC_ROOT', "/var/www/showreel.godotengine.org/static/")
STATIC_URL = '/static/'

View File

@@ -13,9 +13,12 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import path, include
from django.contrib import admin
from django.contrib.auth import views
from django.conf import settings
urlpatterns = [
# Login
@@ -27,4 +30,8 @@ urlpatterns = [
# Vote
path('', include('vote.urls')),
]
]
# Serve static files
if settings.SERVE_STATICS:
urlpatterns += staticfiles_urlpatterns()

View File

@@ -32,8 +32,9 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
root /var/www/showreel.godotengine.org/;
}
# Statics are served by the django app, but could be served by nginx too.
#location /static/ {
# root /var/www/showreel.godotengine.org/;
#}
}
}