Possible to normalize headers in nginx?

Igor Sysoev is at rambler-co.ru
Sat Aug 8 11:00:45 MSD 2009


On Sat, Aug 08, 2009 at 05:28:36AM +0200, Victor Iggy wrote:

> I actually figured out my answer... the configuration is a bit weird but 
> it works...
> 
> is the answer... for anyone who cares.
> 
>         location / {
>             proxy_set_header  X-Real-IP  $remote_addr;
>             proxy_set_header  X-Forwarded-For 
> $proxy_add_x_forwarded_for;
>             proxy_set_header Host $http_host;
> 
>             if ($http_accept_encoding ~ deflate) {
>                 set $normal_encoding "deflate";
>                 proxy_pass http://72.11.142.91:7999;
>                 break;
>             }
>             if ($http_accept_encoding ~ gzip) {
>                 set $normal_encoding "gzip";
>                 proxy_pass http://72.11.142.91:7999;
>                 break;
>             }
>             if ($request_uri ~ 
> "\.(jpeg|jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|ico|swf|mp4|flv|mov|dmg|mkv)") 
> {
>                 set $normal_encoding "";
>                 proxy_pass http://72.11.142.91:7999;
>                 break;
>             }
>             proxy_set_header Accept-Encoding $normal_encoding;
> 
>         }

This 'if ($request_uri ~ "\.(jpeg|jpg|...|mkv)")' should be rewritten as

     location ~ \.(jpeg|jpg|...|mkv)$ {
         proxy_pass http://72.11.142.91:7999;
         proxy_set_header Accept-Encoding "";
         ...
     }

The whole configuration may be

server {


     if ($http_accept_encoding ~ deflate) {
         set $encoding "deflate";
         break;
     }

     if ($http_accept_encoding ~ gzip) {
         set $encoding "gzip";
         break;
     }

     location / {
         proxy_pass http://72.11.142.91:7999;
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
         proxy_set_header  Host $http_host;
         proxy_set_header  Accept-Encoding $encoding;
     }

     location ~ \.(jpeg|jpg|...|mkv)$ {
         proxy_pass http://72.11.142.91:7999;
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
         proxy_set_header  Host $http_host;
         proxy_set_header  Accept-Encoding "";
     }
}

-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list