Forum: NGINX try_files and GET variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Reinis R. (Guest)
on 2009-03-30 17:58
(Received via mailing list)
Hello,
tried to replace the webserver config to use try_files instead of
rewrites (on 0.7.46), it kinda works but I get some garbage in
QUERY_STRING on the php fastcgi backend - so php doesnt see any GET
variable.


The config is simple:

location /tmp {
    try_files $uri /index.php;
}


When I open http://myserver/tmp/?var=1  and dump the $_SERVER variables
'REQUEST_URI' is correct -  '/tmp/?var=1' but QUERY_STRING
gets something like 'H‰H=�' (non-printable chars)




If I change the nginx config to named location everything works as
expected (all the GET variables are passed and QUERY_STRING is
correct):

location /tmp {
    try_files $uri @tmp;
}

location @tmp{
              fastcgi_pass   127.0.0.1:1026;
              fastcgi_index  index.php;
             include        fastcgi_params;
             fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
 }


Where is the catch?


wbr
Reinis R.
Igor S. (Guest)
on 2009-03-30 18:28
(Received via mailing list)
Attachment: patch.try_files.746 (0 Bytes)
On Mon, Mar 30, 2009 at 04:47:21PM +0300, Reinis R. wrote:

> }
> (all the GET variables are passed and QUERY_STRING is correct):
> }
>
>
> Where is the catch?

The attached patch fixes the bug.
Reinis R. (Guest)
on 2009-03-30 19:28
(Received via mailing list)
> The attached patch fixes the bug.

It fixed the garbage part then again QUERY_STRING is now empty at all..
Or is this expected?


In short what I try to archieve is this - if you have:

location /tmp {
    try_files $uri /index.php;
}

And open something like http://myserver/tmp/somecategory/another/?id=234
php still gets 'id' as normal GET variable..



The rewrite or error_page alternative would be:

rewrite  ^/tmp/(.*)$ / last;

location /tmp/ {
        error_page   404 =         /index.php;
}




I somehow see this conflicting if you specify something like this in the
config

location /tmp {
    try_files $uri /index.php?q=$request_uri;
}

Then again it gets messy if you want to split the query_string on php
side and assign all the variables.. Besides try_files looks
way more superior than both previous approaches..


wbr
rr
Igor S. (Guest)
on 2009-03-30 19:59
(Received via mailing list)
On Mon, Mar 30, 2009 at 06:14:25PM +0300, Reinis R. wrote:

> }
>
> And open something like http://myserver/tmp/somecategory/another/?id=234
> php still gets 'id' as normal GET variable..

If you want to preserve query_string, then you should use

    try_files $uri /index.php?$args;
Reinis R. (Guest)
on 2009-03-30 20:42
(Received via mailing list)
> If you want to preserve query_string, then you should use
>
>    try_files $uri /index.php?$args;

Thanks, missed this!
Together with the patch now works perfectly..

rr
This topic is locked and can not be replied to.