Answer the question
In order to leave comments, you need to log in
How to make the function return the absolute path to the file with https and not http?
Guys, need some bright ideas!)
It doesn't work, because the mechanism |generate an absolute link to a file| returns an absolute path with http base and it needs to be https.
In order.
There is a template:
<audio controls onended="startNextTrack()">
<source id="audio_sourse" src="{% url 'stream_mp3' song.name %}">
</audio>
path('stream_mp3/<path:song>', views.stream_mp3, name='stream_mp3')
# внимание! django dev сервер не поддерживает частичный ответ 206 поэтому работает только в nginx
def stream_mp3(request, song):
song_name = song
mp3_path = os.getcwd() + '/media/charge/music/' + song_name
response = HttpResponse('', content_type="audio/mpeg", status=206)
response['X-Accel-Redirect'] = '/media/charge/music/' + song_name
response['X-Accel-Buffering'] = 'no'
response['Content-Length'] = os.path.getsize(mp3_path)
response['Content-Dispostion'] = "attachment; filename=" + mp3_path
response['Accept-Ranges'] = 'bytes'
return response
http://batareika.app/media/charge/music/bi2mojjroknrollmegapesnime.mp3
Answer the question
In order to leave comments, you need to log in
Guys thanks for the help! Everything worked. But I had to do the right thing) that is, not like I did initially. In general, Ruslan
did everything .
For this he is special, thank you very much! 1) Removed qunicorn support from NGINX. 2) Removed all demons from the work logic. 3) Installed UWSGI. 4) Added file: batareika.ini
[uwsgi]
chdir = /root/Batareika
module = Batareika.wsgi
home = /root/Batareika/venv
master = true
processes=6
chmod-socket = 666
socket = /root/Batareika/batareika.sock
upstream batareika {
server unix:////root/Batareika/batareika.sock;
}
server {
listen 80;
server_name batareika.app;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name batareika.app;
ssl_certificate /etc/letsencrypt/live/batareika.app/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/batareika.app/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/Batareika;
}
location /media/ {
root /root/Batareika;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
uwsgi_pass batareika;
include /etc/nginx/uwsgi_params;
}
}
# для NGINX перенаправление траффика http-https
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
host_mp3 = 'https://batareika.app/media/charge/music/'
link = host_mp3 + song_name
# и link летит в шаблон
You are missing settings for https:
settings.py
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
os.getcwd() - why not write a domain with a schema here?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question