# Abstract behavior of nginx

**URL:** <https://www.ruby-forum.com/t/abstract-behavior-of-nginx/237651>\
**Category:** NGINX\
**Created:** [November 22, 2013, 2:48pm UTC](https://www.ruby-forum.com/t/abstract-behavior-of-nginx/237651 "2013-11-22T14:48:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [November 22, 2013, 2:48pm UTC](https://www.ruby-forum.com/t/abstract-behavior-of-nginx/237651/1 "2013-11-22T14:48:00Z")

</div>

Hi,

I can’t understand behavior of nginx.  
Version 1.2.1 on Debian Wheezy from official repository. I send requests  
to cdn.some\_domain.pl server, and in log  
/var/log/nginx/cdn.some\_domain.pl/test.log I see:

image/gif:1  
image/png:1  
image/png:1  
image/gif:1  
image/png:1  
image/gif:1

It is correct. If I remove hash sign in 3 last line of configuration  
file, nginx puts to /var/log/nginx/cdn.some\_domain.pl/test.log below  
entries:

-:0  
-:0  
-:0  
-:0  
-:0  
-:0

I don’t understand, why in this configuration, value of  
$sent\_http\_content\_type variable is empty.

Configuration:

user www-data;  
worker\_processes 4;  
pid /var/run/nginx.pid;  
events {  
worker\_connections 768;  
}  
http {  
sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;  
keepalive\_timeout 65;  
types\_hash\_max\_size 2048;  
server\_tokens off;  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;  
gzip on;  
gzip\_disable “msie6”;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Forwarded-Host $host;  
proxy\_set\_header X-Forwarded-Server $host;

```
            map $sent_http_content_type $cdn {
                           default 0;
                           text/css 1;
                           text/javascript 1;
                           image/x-icon 1;
                           image/gif 1;
                           image/jpeg 1;
                           image/png 1;
            }

            log_format test $sent_http_content_type:$cdn;

```

server {  
listen 82 default; ## listen for ipv4  
listen [::]:82 default ipv6only=on; ## listen for ipv6  
server\_name localhost “”;  
access\_log /var/log/nginx/localhost.access.log;  
error\_log /var/log/nginx/localhost.error.log;  
location / {  
root /var/www;  
index index.html index.htm;  
}  
location /test.txt {  
proxy\_pass http://$server\_addr:8080;  
}  
}

server {  
listen 82;  
server\_name cdn.some\_domain.pl;  
location / {  
proxy\_pass http://$server\_addr:8080;  
}  
location /test.jsp {  
proxy\_pass http://$server\_addr:8080;  
allow 10.0.0.0/8;  
deny all;  
}  
access\_log /var/log/nginx/cdn.some\_domain.pl/test.log  
test;

# if ($cdn) {

# return 404;

# }

}  
}

Regards,  
Jarek

---

<div class="post-metadata">

**Author:** ![SSPomorski\_JarosSSa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@SSPomorski\_JarosSSa](https://www.ruby-forum.com/u/SSPomorski_JarosSSa)\
**Post date:** [November 26, 2013, 11:57am UTC](https://www.ruby-forum.com/t/abstract-behavior-of-nginx/237651/2 "2013-11-26T11:57:21Z")

</div>

Hello,

It makes sense… Thank you for your help.

Regards,  
Jarek

---

<div class="post-metadata">

**Author:** ![SSPomorski\_JarosSSa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@SSPomorski\_JarosSSa](https://www.ruby-forum.com/u/SSPomorski_JarosSSa)\
**Post date:** [November 25, 2013, 2:32pm UTC](https://www.ruby-forum.com/t/abstract-behavior-of-nginx/237651/3 "2013-11-25T14:32:31Z")

</div>

Hello!

On Fri, Nov 22, 2013 at 02:47:23PM +0100, Pomorski Jarosław wrote:

> image/gif:1  
> -:0  
> -:0  
> -:0
> 
> I don’t understand, why in this configuration, value of  
> $sent\_http\_content\_type variable is empty.

[…]

> ```
> map $sent_http_content_type $cdn {
> default 0;
> text/css 1;
> text/javascript 1;
> image/x-icon 1;
> image/gif 1;
> image/jpeg 1;
> image/png 1;
> }
> 
> ```

[…]

> # if ($cdn) {
> 
> # return 404;
> 
> # }

The “if ($cdn)” is evaluated while processing rewrite rules, and  
at this point value of $sent\_http\_content\_type isn’t yet known  
(because response isn’t sent). But due to this evaluation  
calculated values of the $sent\_http\_content\_type and $cdn  
variables are cached, and not re-evaluated again later.

That is, what you see in logs is a value of the  
$sent\_http\_content\_type variable at the time the variable was  
evaluated for the first time during request processing.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)
