Add private media server using nginx

Use internal nginx root with X-Accel-Redirect header
This commit is contained in:
Edgar P. Burkhart 2022-12-21 14:23:02 +01:00
parent 65af7105b2
commit 043f5e7112
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
4 changed files with 20 additions and 2 deletions

View file

@ -12,4 +12,9 @@ server {
location /static {
alias /srv/nummi;
}
location /media {
internal;
alias /var/lib/nummi;
}
}

View file

@ -16,7 +16,7 @@ import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
MEDIA_ROOT = Path(os.environ.get("NUMMI_MEDIA_ROOT", "/var/lib/nummi"))
MEDIA_URL = "files/"
MEDIA_URL = "media/"
# Quick-start development settings - unsuitable for production

View file

@ -20,7 +20,11 @@ from django.views.generic.base import RedirectView
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = i18n_patterns(
from . import views
urlpatterns = [
path("media/", views.media, name="media"),
] + i18n_patterns(
path("", include("main.urls")),
path("plot/", include("plot.urls")),
path("admin/", admin.site.urls),

9
nummi/nummi/views.py Normal file
View file

@ -0,0 +1,9 @@
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
@login_required
def media(request):
_res = HttpResponse()
_res["Content-Type"] = ""
_res["X-Accel-Redirect"] = request.path
return _res