Answer the question
In order to leave comments, you need to log in
Nginx+django problems serving private static files
There is such a task for the development process (not deploy yet):
When you click on the link, say 127.0 . before giving a response, you need to check that the user has access to the file (that is, that he could not access other people's files).
I'm looking at nginx and the X-Accel-Redirect response headers. At this stage, I do not want to use the built-in web server (runserver) in Jung, so that it would be easier to debug.
How to properly organize such access (gett url -> django view -> nginx static serve)? Via react-redirect?
While I'm trying to use this construction:
view:
def get(self, request, *args, **kwargs):
audio_file = self.get_object()
ogg_file_version = audio_file.audiofileversion_set.filter(format="ogg")
if ogg_file_version.exists():
ogg_file_version = ogg_file_version[0]
res = HttpResponse()
res["Content-type"] = "audio/ogg"
res["X-Accel-Redirect"] = ogg_file_version.file.path
res["Content-length"] = ogg_file_version.file.size
return res
return Http404()
server {
listen 80;
gzip off;
expires off;
location /static/ {
add_header X-Static hit;
autoindex on;
expires off;
root /Users/andrewshkovskii/workspace/ip_pbx/;
}
location / {
proxy_pass http://localhost:8000;
rewrite ^/audiofiles/get/(\d+)/ /audiofiles/serve/$1/ last;
}
location /media/audio {
internal;
root /var/ip_pbx/users;
}
}
Answer the question
In order to leave comments, you need to log in
Solved by config
server {
listen 80;
gzip off;
expires off;
error_log /usr/local/Cellar/nginx/1.2.5/logs/error.log debug;
location /static/ {
add_header X-Static hit;
autoindex on;
expires off;
root /Users/andrewshkovskii/workspace/ip_pbx/;
}
location / {
proxy_pass http://localhost:8000;
rewrite ^/audiofiles/get/(\d+)/ /audiofiles/serve/$1/ last;
}
location ~ /var/ip_pbx/users_andrewshkovskii/(\d+)/(audio|calls)/(.*) {
internal;
root /;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question