Forum: NGINX Header modification with X-Accel-Redirect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
26b5a272f4f1854748e2a6fda356573a?d=identicon&s=25 Brice Leroy (Guest)
on 2009-05-21 01:54
(Received via mailing list)
Hi,
   I'm using X-Accel-Redirect and I would like to log modified header
information at the same time. But when X-Accel-Redirect clear  return
his own header , so I can never get the clip variable :(

- Brice

My Django view
...
    response = HttpResponse(status=200)
     response['Cache-Control'] = 'no-cache'
     response['Pragma'] = 'no-cache'
     response['Content-Type'] = ""
     response['clip'] = one_time_access.clip.id
     response['method'] = 'one_time_access_view'
     response['X-Accel-Redirect'] = url
     return response

and my nginx configuration:

server {
     listen   80;
     server_name xxx.yyy.com;

     log_format main
    '[$time_local]\n'
         'ip=$remote_addr\n'
         'request="$request"\n'
         'bytes=$body_bytes_sent\n'
    'clipid=$sent_http_clip\n'
    'method=$sent_http_method\n'
    '"$sent_http_pragma"=$sent_http_pragma'
    '_EOE_\n';

     access_log  /home/kev/logs/access.log main;
     error_log  /home/kev/logs/error.log;

     #add_header           Front-End-Https    on;

     location / {
         proxy_pass http://127.0.0.1:8899/;
         #proxy_set_header X-Forwarded-Protocol "https";
         proxy_set_header  Host       $host;
         proxy_set_header  X-Real-IP  $remote_addr;
         client_max_body_size       3000m;
  }

     location /media/ {
         alias /home/kev/clipbuilder/media/;
  internal;
     }

     location /static/ {
         alias /home/kev/clipbuilder/static/;
     }

     location /adminmedia/ {
         alias /usr/local/src/django-trunk/django/contrib/admin/media/;
     }

     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
  root   /var/www/nginx-default;
     }
}
26b5a272f4f1854748e2a6fda356573a?d=identicon&s=25 Brice Leroy (Guest)
on 2009-05-21 02:10
(Received via mailing list)
My previous email was maybe unclear. I'm trying to log the bandwidth
usage per clip I serve. because every clip are static file, I'm using
x-accel-redirect to serve them. So I'm adding clip value to the header
to log it using nginx with body_bytes_sent so I can know how much
bandwidth has been used for this clip. But it seams that using  x-
accel-redirect doesn't allow header modification because my log don't
get the information. But if I remove the x-accel-redirect (of course
in this case I don't get the file) the clip value injected in the
header appear in my logs ! Any idea to make this value appear when I
use X-Accel-Redirect ?

Thanks :)

Brice

Begin forwarded message:
0c31ca11d92038571de52b53c8ad4a8a?d=identicon&s=25 Denis F. Latypoff (Guest)
on 2009-05-21 07:13
(Received via mailing list)
Hello Brice,

Thursday, May 21, 2009, 7:03:38 AM, you wrote:

> My previous email was maybe unclear. I'm trying to log the bandwidth
> usage per clip I serve. because every clip are static file, I'm using
> x-accel-redirect to serve them. So I'm adding clip value to the header
> to log it using nginx with body_bytes_sent so I can know how much
> bandwidth has been used for this clip. But it seams that using  x-
> accel-redirect doesn't allow header modification because my log don't
> get the information. But if I remove the x-accel-redirect (of course
> in this case I don't get the file) the clip value injected in the
> header appear in my logs ! Any idea to make this value appear when I
> use X-Accel-Redirect ?

    location /media/ {
        add_header   clip    $upstream_http_clip;
        add_header   method  $upstream_http_method;
        alias /home/kev/clipbuilder/media/;
        internal;
    }

> Thanks :)

> Brice

> Begin forwarded message:

>> - Brice
>>    return response
>>               'request="$request"\n'
>>
>>       internal;
>>    error_page   500 502 503 504  /50x.html;
>>    location = /50x.html {
>>       root   /var/www/nginx-default;
>>    }
>> }
>>




> __________ NOD32 4090 (20090520) Information __________
26b5a272f4f1854748e2a6fda356573a?d=identicon&s=25 Brice Leroy (Guest)
on 2009-05-27 00:33
(Received via mailing list)
Thanks Denis ! It's working.

NGinx rocks !
This topic is locked and can not be replied to.