Welcome! Log In Create A New Profile

Advanced

Re: ngx_lua location capture issue

Nginx User
October 18, 2011 01:30PM
On 18 October 2011 20:28, Nginx User <nginx@nginxuser.net> wrote:
> On 18 October 2011 19:55, Nginx User <nginx@nginxuser.net> wrote:
>> 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
>>
>
>
> A more considered read of the docs shows I had been mixingsubrequests
> and internal redirections all over the place and that this works as
> expected
>
>
> # GET /test_page.php
> server {
>        listen 80;
>        server_name testsite.com;
>        root /home/user/testsite.com/public_html;
>        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$ {
>                        access_by_lua '
>                                local res = ngx.location.capture("/phpids")
>                                if res.status == ngx.HTTP_OK then
>                                        ngx.exec("@proxy_no_cache")
>                                end
>                                if res.status == ngx.HTTP_FORBIDDEN then
>                                        ngx.exit(res.status)
>                                end
>                                ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
>                        ';
>                }
>
>                rewrite_by_lua 'ngx.exec("@proxy");';
>        }
> }
>
>
> No need for @checkpoint. Just put the access check directly in place.
>
> Cool beans!
>

"@proxy_no_cache" = "@proxy"

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

ngx_lua location capture issue

Nginx User October 18, 2011 12:56PM

Re: ngx_lua location capture issue

Nginx User October 18, 2011 01:30PM

Re: ngx_lua location capture issue

Nginx User October 18, 2011 01:30PM

Re: ngx_lua location capture issue

Nginx User October 18, 2011 02:00PM

Re: ngx_lua location capture issue

agentzh October 18, 2011 10:42PM

Re: ngx_lua location capture issue

agentzh October 18, 2011 10:50PM

Re: ngx_lua location capture issue

Nginx User October 19, 2011 12:46PM

Re: ngx_lua location capture issue

agentzh October 18, 2011 10:34PM

Re: ngx_lua location capture issue

agentzh October 19, 2011 05:26AM

Re: ngx_lua location capture issue

Nginx User October 19, 2011 02:12PM

Re: ngx_lua location capture issue

agentzh October 19, 2011 08:44PM

Re: ngx_lua location capture issue

Nginx User October 20, 2011 04:28AM

Re: ngx_lua location capture issue

agentzh October 20, 2011 04:48AM

Re: ngx_lua location capture issue

Nginx User October 20, 2011 06:50AM

Re: ngx_lua location capture issue

agentzh October 20, 2011 07:50AM

Re: ngx_lua location capture issue

Nginx User October 20, 2011 12:04PM

Re: ngx_lua location capture issue

agentzh October 21, 2011 12:10AM

Re: ngx_lua location capture issue

agentzh October 21, 2011 12:14AM

Re: ngx_lua location capture issue

Nginx User October 21, 2011 03:36AM

Re: ngx_lua location capture issue

Nginx User October 21, 2011 03:56AM

Re: ngx_lua location capture issue

Nginx User October 21, 2011 10:02AM

Re: ngx_lua location capture issue

Nginx User October 21, 2011 10:28AM

Re: ngx_lua location capture issue

Nginx User October 21, 2011 10:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 176
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready