You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting Nginx 404 Not Found instead of protected media which is image in my case.
Kindly asking for a help because I don't understand what I am doing wrong.
In settings.py I have this:
PROTECTED_MEDIA_ROOT=os.path.join(BASE_DIR, 'protected')
PROTECTED_MEDIA_URL="/protected"PROTECTED_MEDIA_SERVER="nginx"# Defaults to "django"PROTECTED_MEDIA_LOCATION_PREFIX="/internal"# Prefix used in nginx configPROTECTED_MEDIA_AS_DOWNLOADS=False# Controls inclusion of a Content-Disposition header
In django I have this:
@login_requireddefmy_media_access(request, media_object, file_relpath):
# some code to check if access is grantedifaccess_granted:
returnprotected_view(request, file_relpath, server=PROTECTED_MEDIA_SERVER, as_download=PROTECTED_MEDIA_AS_DOWNLOADS)
returnHttpResponseForbidden('Not authorized to access this media.')
So the files are in folder /home/myuser/myproject/protected.
Idea is that when you access URL https://example.com/protected/abc/image/4813-image1.png then Django recognizes this path and calls protected_view in django-protected-media.
This are the test results for logged in user which is allowed to see asset:
opening https://example.com/protected/abc/image/4813-image1.png - 404 Not Found (nginx) which is NOT OK, image should be shown
opening https://example.com/internal/abc/image/4813-image1.png - 404 Not Found (nginx) which is OK
opening https://example.com/protected/abc/image/4813-image1_WRONG_PATH.png - Django message that there is no route which is OK
The text was updated successfully, but these errors were encountered:
I'm getting Nginx 404 Not Found instead of protected media which is image in my case.
Kindly asking for a help because I don't understand what I am doing wrong.
In
settings.py
I have this:In django I have this:
In Nginx configuration I have:
So the files are in folder
/home/myuser/myproject/protected
.Idea is that when you access URL
https://example.com/protected/abc/image/4813-image1.png
then Django recognizes this path and callsprotected_view
indjango-protected-media
.This are the test results for logged in user which is allowed to see asset:
https://example.com/protected/abc/image/4813-image1.png
- 404 Not Found (nginx) which is NOT OK, image should be shownhttps://example.com/internal/abc/image/4813-image1.png
- 404 Not Found (nginx) which is OKhttps://example.com/protected/abc/image/4813-image1_WRONG_PATH.png
- Django message that there is no route which is OKThe text was updated successfully, but these errors were encountered: