user  usr usr;
worker_processes  2;

http {
    types {
        text/javascript    js;
        application/xml    xml;
    }
 
    # By default, return content sa
    default_type  application/xml;

    access_log  /home/api/logs/nginx.log  main;

    sendfile       on;
    tcp_nopush     on;

    keepalive_timeout  65;
    tcp_nodelay        on;

    # app. server(s) / cluster definition
    upstream dynamic_srv { server 127.0.0.1:9020; }

    server {
        listen       9000;
        server_name  srv;
        root        /home/usr;
        
	# Match any request that begins with /dynamic_request
        location /dynamic_request {
	   
	   # Append a file-extension to every request
           if ($args ~* format=json) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.js$1 break; }
           if ($args ~* format=xml)  { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.xml$1 break; }
           
	   # Check if local memcached server can answer this request
           memcached_pass 127.0.0.1:11211;

	   # Send to app. server if Memcached could not ansewr the request
           error_page 404 = @dynamic_request;
        }

        location @dynamic_feed_id { 
            # only internal requests can reach this endpoint
            internal; 

            # dispatch to our app_server cluster / instance
            proxy_pass http://dynamic_srv;
        }     
      
    }
}
