Forum: NGINX The two slashes issue - or how to append a constant to a parameter.

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.
Ian H. (Guest)
on 2009-02-06 13:53
(Received via mailing list)
Hi

I have a situation that I have had to fix using set...

        # handle directory names by adding /index.htm
        location ~ ^(.*)/$ {
                # matches directories
                set $path index.htm;
                fastcgi_param QUERY_STRING f=$request_uri$path;
                fastcgi_param DOCUMENT_ROOT $document_root;
                fastcgi_param SCRIPT_FILENAME
/var/www/builder/parser.php;
                fastcgi_pass 127.0.0.1:9000;
        }

The issue was that with

fastcgi_param QUERY_STRING f=$request_uri/index.htm;

I was getting two slashes - one added by nginx and one on the line
above, even if the entered URI contained none.

Is there a better way of adding a constant after a parameter?

Regards

Ian
Igor S. (Guest)
on 2009-02-06 14:34
(Received via mailing list)
On Fri, Feb 06, 2009 at 11:42:13AM +0000, Ian H. wrote:

>                fastcgi_param SCRIPT_FILENAME /var/www/builder/parser.php;
>                fastcgi_pass 127.0.0.1:9000;
>        }
>
> The issue was that with
>
> fastcgi_param QUERY_STRING f=$request_uri/index.htm;
>
> I was getting two slashes - one added by nginx and one on the line
> above, even if the entered URI contained none.

> Is there a better way of adding a constant after a parameter?

Yes:

        location ~ ^(.*)/$ {
                # matches directories
-               set $path index.htm;
+               fastcgi_index index.htm;
-               fastcgi_param QUERY_STRING f=$request_uri$path;
+               fastcgi_param QUERY_STRING
f=$fastcgi_script_name$is_args$args;
                fastcgi_param DOCUMENT_ROOT $document_root;
                fastcgi_param SCRIPT_FILENAME
/var/www/builder/parser.php;
                fastcgi_pass 127.0.0.1:9000;
        }
Igor S. (Guest)
on 2009-02-06 14:57
(Received via mailing list)
On Fri, Feb 06, 2009 at 11:42:13AM +0000, Ian H. wrote:

>                fastcgi_param SCRIPT_FILENAME /var/www/builder/parser.php;
> Is there a better way of adding a constant after a parameter?
I did not read thoughtfully, you may use

- fastcgi_param QUERY_STRING f=$request_uri/index.htm;
+ fastcgi_param QUERY_STRING f=${request_uri}index.htm;

However, $request_uri is not good choice for this as it may have query
string:

     /dir/?one=1&two2
This topic is locked and can not be replied to.