Add private media server using nginx
Use internal nginx root with X-Accel-Redirect header
This commit is contained in:
parent
65af7105b2
commit
043f5e7112
4 changed files with 20 additions and 2 deletions
|
@ -12,4 +12,9 @@ server {
|
||||||
location /static {
|
location /static {
|
||||||
alias /srv/nummi;
|
alias /srv/nummi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /media {
|
||||||
|
internal;
|
||||||
|
alias /var/lib/nummi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import os
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
MEDIA_ROOT = Path(os.environ.get("NUMMI_MEDIA_ROOT", "/var/lib/nummi"))
|
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
|
# Quick-start development settings - unsuitable for production
|
||||||
|
|
|
@ -20,7 +20,11 @@ from django.views.generic.base import RedirectView
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
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("", include("main.urls")),
|
||||||
path("plot/", include("plot.urls")),
|
path("plot/", include("plot.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|
9
nummi/nummi/views.py
Normal file
9
nummi/nummi/views.py
Normal 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
|
Loading…
Reference in a new issue