ngx_lua location capture issue

Nginx User nginx at nginxuser.net
Tue Oct 18 16:55:00 UTC 2011


I tried to create the following scenario:

1. Request test_page.php
2. lua exec to @checkpoint
3. @checkpoint does capture location to test_loc (future phpids)
4. test_loc/index.php returns either 200 or 403 status
5. @checkpoint continues or halts request accordingly

# GET /test_page.php
server {
	listen 80;
	server_name testsite.com;
	root /home/user/testsite.com/public_html;
	location @checkpoint {
        access_by_lua '
            local res = ngx.location.capture("/test_loc")

            if res.status == ngx.HTTP_OK then
                return
            end

            if res.status == ngx.HTTP_FORBIDDEN then
                ngx.exit(res.status)
            end

            ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
        ';
    }
	location @proxy {
		include /etc/nginx/firewall.default;
		
		# Block IPs in Spamhaus drop list
		if ($block = 1) {
			return 444;
		}
		
		proxy_pass http://127.0.0.1:8080;
		...
	}
	location /error_docs {
		internal;
		alias /home/user/$host/error_docs;
	}
	location /test_loc {
		internal;
		alias /usr/share/test_loc/;
		rewrite_by_lua 'ngx.exec("@proxy");';
	}
	location / {
		try_files $uri $uri/ @proxy;
	}
	location ~ .+\.php$ {
		location ~ ^/test_page\.php$ {
			rewrite_by_lua 'ngx.exec("@checkpoint");';
		}
		
		rewrite_by_lua 'ngx.exec("@proxy");';
	}
}

Result is "the http output chain is empty while connecting to
upstream" blah blah blah and output is equivalent to issuing "return
444". http://pastebin.com/7WisVBDU

Logs seem to show "GET /test_page.php" being run a second time.

Any tips on fixing?

Cheers



More information about the nginx mailing list