I'm trying to create a config that doesn't log the requests from specific
user agents. The site has a gunicorn backend that we proxy to, and I'm
trying to set up try_files to test for the existence of static local files
before proxying to the back-end.

The try_files config is the new part, everything was working fine before I
added that.

Here's the nginx.conf I'm using for testing:

user  nginx;
worker_processes  8;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
        upstream backend {
                server 127.0.0.1:8004;
        }

        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request"
$status $body_bytes_sent "$http_referer" "$http_user_agent"
"$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;

        map $http_user_agent $ignore_ua {
                default 0;
                "test-agent" 1;
        }

        server {
                listen       80;
                proxy_redirect off;
                proxy_set_header Host $http_host;
                proxy_set_header Accept-Encoding "";

                location @gunicorn {
                        proxy_pass http://backend$uri$args;
                        add_header X-Cached $upstream_cache_status;
                }

                location / { 
#                       if ($ignore_ua) { access_log off; }
                        try_files $uri/index.cchtml @gunicorn;
                }
        }
}



With the "if" statement commented out, the requests work as I expect them:

curl -s -D- -A test-agent http://site.ordprofile01.example.net/uri/ | head
-n 20

HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Fri, 23 May 2014 16:11:38 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Cookie

<!DOCTYPE html><!--[if lt IE 7]>...

If I uncomment the "if" statement I see this instead:

curl -s -D- -A test-agent http://site.ordprofile01.example.net/uri/ | head
-n 20

HTTP/1.1 404 Not Found
Server: nginx/1.6.0
Date: Fri, 23 May 2014 16:11:24 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.6.0</center>
</body>
</html>

What am I doing wrong here?

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,250325,250325#msg-250325

_______________________________________________
nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Reply via email to