x-accel-redirect

Serving protected files with Django and Nginx X-accel-redirect

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-30 07:46:28
问题 I'm trying to get Nginx and Django to play together to serve downloadable protected files. I just cannot get it to work. Here's my Nginx config: location ~ ^.*/protected-test/ { alias /<path-to-my-protected-files-on-server>/; internal; } the relevant urls.py for viewing the file(s): url(r'^static_files/downloads/protected-test/(?P<filename>.+)$', 'download_or_view', {'download_dir': '%s%s' % (settings.MEDIA_ROOT, 'downloads/protected-test/'), 'content_disposition_type': 'inline', 'protected':

Django Nginx X-Accel-Redirect for protected files on Webfaction

≡放荡痞女 提交于 2019-12-23 04:16:35
问题 If you want to torment someone until the end of time, just get them to configure Django and Nginx X-Accel-Redirect. This is literally impossible, I have been trying for days. I am trying to only allow certain files to be downloaded from logged in views in django using Nginx on webfaction. Here is what I have: Custom Nginx app listening on port 27796 under /static. Here is the conf. http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server {

Nginx serving static files with 404 status code?

懵懂的女人 提交于 2019-12-12 04:40:07
问题 I'm trying to let Nginx serve my authenticated admin users some static files with PHP. This works great, I get back the file. But it's served with a 404 status code.. I'm using the following (Symfony / Silex) php code: use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\ResponseHeaderBag; $filePath = '/usr/share/nginx/project/src/path/to/my/protected/static/dir/' . $file; if (empty($file) || !is_readable($filePath)) { $app->abort(404); } $response =

Serving protected files with Symfony2 and Nginx X-accel-redirect

纵然是瞬间 提交于 2019-12-11 02:23:17
问题 My config is php-fpm 5.4 with nginx. I need to serve some protected files. So I check with Symfony if the user has the correct rights and then I would like nginx to serve the file (a swf) using the X-accel-redirect header. Controller in symfony: /** * @Route("/protected/swf") */ public function sendFileAction() { // [...] // user rights are ok, serve the file $fileName = 'myfile.swf'; $filePath = $this->get('kernel')->getRootDir() . '/../files/' . $fileName; $response = new BinaryFileResponse

Django Nginx X-Accel-Redirect for protected files on Webfaction

孤街醉人 提交于 2019-12-06 15:45:02
If you want to torment someone until the end of time, just get them to configure Django and Nginx X-Accel-Redirect. This is literally impossible, I have been trying for days. I am trying to only allow certain files to be downloaded from logged in views in django using Nginx on webfaction. Here is what I have: Custom Nginx app listening on port 27796 under /static. Here is the conf. http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 27796; server_name myurl.com; root /home/ucwsri/webapps/static_media_ucwsri_nginx; location / {

Different behavour of “location” and “proxy_pass” on nginx x-accel-redirect

℡╲_俬逩灬. 提交于 2019-12-02 12:45:40
问题 I have my nginx conf like : location ^~ /mount_points/mount_point1 { internal; alias /repos/mount_point_one; } location ^~ /to_proxy { internal; proxy_pass http://myproxy:5000; } When I request for 'http://localhost/mount_points/mount_point1/myfile.zip' I get "/repos/mount_point_one/myfile.zip" as expected. While request for 'http://localhost/to_proxy/myfile2.html', I get "http://myproxy:5000/to_proxy/myfile2.html". In the first case, the "/mount_points/mount_point1" part was removed, and in

Nginx pass upstream headers to the remote request

一曲冷凌霜 提交于 2019-12-02 04:28:49
问题 This question is similar to this one but doing x-accel-redirect on aws s3 resource. The former tried to set the upstream headers to the local request. This works fine. But now i have moved my contents to the amazon s3 and i wanted to implement the same restricted download to the s3 objects. This is my nginx config proxy_pass_header X-Accel-Redirect; passenger_pass_header X-Accel-Redirect; location ~* ^/download_zip/(.*) { internal; resolver 8.8.8.8 valid=300s; proxy_buffering off; proxy_set

Different behavour of “location” and “proxy_pass” on nginx x-accel-redirect

核能气质少年 提交于 2019-12-02 03:13:28
I have my nginx conf like : location ^~ /mount_points/mount_point1 { internal; alias /repos/mount_point_one; } location ^~ /to_proxy { internal; proxy_pass http://myproxy:5000; } When I request for ' http://localhost/mount_points/mount_point1/myfile.zip ' I get "/repos/mount_point_one/myfile.zip" as expected. While request for ' http://localhost/to_proxy/myfile2.html ', I get " http://myproxy:5000/to_proxy/myfile2.html ". In the first case, the "/mount_points/mount_point1" part was removed, and in the second case, the "/to_proxy" part still there, I have to fake a "/to_proxy" address in the

Nginx pass upstream headers to the remote request

。_饼干妹妹 提交于 2019-12-02 02:51:23
This question is similar to this one but doing x-accel-redirect on aws s3 resource. The former tried to set the upstream headers to the local request. This works fine. But now i have moved my contents to the amazon s3 and i wanted to implement the same restricted download to the s3 objects. This is my nginx config proxy_pass_header X-Accel-Redirect; passenger_pass_header X-Accel-Redirect; location ~* ^/download_zip/(.*) { internal; resolver 8.8.8.8 valid=300s; proxy_buffering off; proxy_set_header Content-Length ""; proxy_set_header Cookie ""; proxy_hide_header x-amz-request-id; proxy_hide

Adding custom HTTP headers to nginx X-Accel-Redirect

被刻印的时光 ゝ 提交于 2019-11-30 08:45:34
问题 I am serving restricted downloads in rails using X-Accel-Redirect with nginx. To validate my downloads in client app, i am trying to send the checksum in the non standard HTTP header Content-MD5 to the X-Accel-Redirect request. But this is not working. below the rails snippet used to do the redirection headers['X-Accel-Redirect'] = '/download_public/uploads/stories/' + params[:story_id] +'/' + params[:story_id] + '.zip' headers['X-Accel-Expires'] = 'max' checksum = Digest::MD5.file(Rails.root