Forum: NGINX Abstract behavior of nginx

8d32afef77e5378a29b44a69d7794146?d=identicon&s=25 "Pomorski Jarosław" <JPomorski@wolterskluwer.pl> (Guest)
on 2013-11-22 14:48
(Received via mailing list)
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
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-11-25 14:32
(Received via mailing list)
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 Dounin
http://nginx.org/en/donation.html
8d32afef77e5378a29b44a69d7794146?d=identicon&s=25 "Pomorski Jarosław" <JPomorski@wolterskluwer.pl> (Guest)
on 2013-11-26 11:57
(Received via mailing list)
Hello,

It makes sense... Thank you for your help.

Regards,
Jarek
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.