foswiki and nginx

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

foswiki and nginx

Chris Hoefler
Hi,

We are attempting to use Foswiki with Nginx. I followed the instructions in,
http://foswiki.org/Extensions/FastCGIEngineContrib

to set up a proper nginx.conf file with the foswiki.fcgi process running in the background. The instructions were fine except for one problem. Logging in and viewing topics worked, but saving topics returned a 405 error. Editing one of the location settings fixed the problem,

        location ~ ^/bin {
                try_files $uri @foswiki;
                error_page 405 = @foswiki;
        }

Now, everything seems to work well...except request validation. When a request validation is necessary, the server does not seem to do a proper hand off to the fastcgi backend. I get the following returned from the server,

#! /usr/bin/perl -wT # See bottom of file for license and copyright information use strict; use warnings; BEGIN { if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; use CGI::Carp qw(fatalsToBrowser); $SIG{__DIE__} = \&CGI::Carp::confess; } else { $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; require Carp; $SIG{__DIE__} = \&Carp::confess; } $ENV{FOSWIKI_ACTION} = 'save'; @INC = ( '.', grep { $_ ne '.' } @INC ); require 'setlib.cfg'; } use Foswiki (); use Foswiki::UI (); $Foswiki::engine->run(); __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors are listed in the AUTHORS file in the root of this distribution. NOTE: Please extend that file, not this notice. Additional copyrights apply to some or all of the code in this file as follows: Copyright (C) 1999-2007 Peter Thoeny, [hidden email] and TWiki Contributors. All Rights Reserved. TWiki Contributors are listed in the AUTHORS file in the root of this distribution. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. For more details read LICENSE in the root of this distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. As per the GPL, removal of this notice is prohibited.

Does anybody have any insight into how to go about fixing this? As far as I can tell from the location rules, the request should be processed through the @foswiki block. My @foswiki block looks like this,

        location @foswiki {
                gzip off;

                fastcgi_pass 127.0.0.1:9000;
                fastcgi_split_path_info  ^/bin/(.+?)(/.*)$;
                fastcgi_param SCRIPT_FILENAME /mnt/foswiki/Foswiki-1.1.9/bin/foswiki.fcgi;
                fastcgi_param PATH_INFO $fastcgi_path_info;

                include fastcgi_params;
        }


Thanks,
Chris

------------------------------------------------------------------------------

_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|

Re: foswiki and nginx

Michael Daum-2
Hi Chris,

have a look at http://foswiki.org/Support/FoswikiOnNginx
I've attached my setup at the bottom of the page. So far everything works all fine.
Maybe there is something in there that helps you sorting out the issue that you have.

Michael.

On Monday 31 March 2014 12:01:25 Chris Hoefler wrote:

> Hi,
>
> We are attempting to use Foswiki with Nginx. I followed the instructions in,
> http://foswiki.org/Extensions/FastCGIEngineContrib
>
> to set up a proper nginx.conf file with the foswiki.fcgi process running in
> the background. The instructions were fine except for one problem. Logging
> in and viewing topics worked, but saving topics returned a 405 error.
> Editing one of the location settings fixed the problem,
>
>         location ~ ^/bin {
>                 try_files $uri @foswiki;
>                 error_page 405 = @foswiki;
>         }
>
> Now, everything seems to work well...except request validation. When a
> request validation is necessary, the server does not seem to do a proper
> hand off to the fastcgi backend. I get the following returned from the
> server,
>
> #! /usr/bin/perl -wT # See bottom of file for license and copyright
> information use strict; use warnings; BEGIN { if ( defined
> $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { $Foswiki::cfg{Engine}
> = 'Foswiki::Engine::CGI'; use CGI::Carp qw(fatalsToBrowser); $SIG{__DIE__}
> = \&CGI::Carp::confess; } else { $Foswiki::cfg{Engine} =
> 'Foswiki::Engine::CLI'; require Carp; $SIG{__DIE__} = \&Carp::confess; }
> $ENV{FOSWIKI_ACTION} = 'save'; @INC = ( '.', grep { $_ ne '.' } @INC );
> require 'setlib.cfg'; } use Foswiki (); use Foswiki::UI ();
> $Foswiki::engine->run(); __END__ Foswiki - The Free and Open Source Wiki,
> http://foswiki.org/ Copyright (C) 2008-2010 Foswiki Contributors. Foswiki
> Contributors are listed in the AUTHORS file in the root of this
> distribution. NOTE: Please extend that file, not this notice. Additional
> copyrights apply to some or all of the code in this file as follows:
> Copyright (C) 1999-2007 Peter Thoeny, [hidden email] and TWiki
> Contributors. All Rights Reserved. TWiki Contributors are listed in the
> AUTHORS file in the root of this distribution. This program is free
> software; you can redistribute it and/or modify it under the terms of the
> GNU General Public License as published by the Free Software Foundation;
> either version 2 of the License, or (at your option) any later version. For
> more details read LICENSE in the root of this distribution. This program is
> distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
> without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE. As per the GPL, removal of this notice is prohibited.
>
> Does anybody have any insight into how to go about fixing this? As far as I
> can tell from the location rules, the request should be processed through
> the @foswiki block. My @foswiki block looks like this,
>
>         location @foswiki {
>                 gzip off;
>
>                 fastcgi_pass 127.0.0.1:9000;
>                 fastcgi_split_path_info  ^/bin/(.+?)(/.*)$;
>                 fastcgi_param SCRIPT_FILENAME
> /mnt/foswiki/Foswiki-1.1.9/bin/foswiki.fcgi;
>                 fastcgi_param PATH_INFO $fastcgi_path_info;
>
>                 include fastcgi_params;
>         }
>
>
> Thanks,
> Chris


--
-- Michael Daum Consulting
-- Wissensmanagement und Intranet-Technologie
-- http://michaeldaumconsulting.com
-- Tel: +49 (0)40 21 99 27 51

------------------------------------------------------------------------------
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|

Re: foswiki and nginx

Chris Hoefler
Hi Michael,

Thanks for the info. I did actually follow the instructions on that page as well. If it's working for others, I'm wondering if it is a difference in Nginx version (I'm using 1.4.1). I believe my nginx.conf conforms to what the guides say. I had to make a few changes due to some slight differences in our setup. The nginx debug log sheds some light on the issue. Here is how a request to /bin/save is being processed,
       
2014/03/31 16:16:31 [debug] 32244#0: *22 http header: "Authorization: Basic Zm9zd2lraWFkbWluOkFzTkgyLWNtbXA="
2014/03/31 16:16:31 [debug] 32244#0: *22 http header: "Connection: keep-alive"
2014/03/31 16:16:31 [debug] 32244#0: *22 http header done
2014/03/31 16:16:31 [debug] 32244#0: *22 generic phase: 0
2014/03/31 16:16:31 [debug] 32244#0: *22 rewrite phase: 1
2014/03/31 16:16:31 [debug] 32244#0: *22 test location: "/"
2014/03/31 16:16:31 [debug] 32244#0: *22 test location: ~ "/bin/configure"
2014/03/31 16:16:31 [debug] 32244#0: *22 test location: ~ "^/pub/(System|Applications|images|cache)/"
2014/03/31 16:16:31 [debug] 32244#0: *22 test location: ~ "^/bin"
2014/03/31 16:16:31 [debug] 32244#0: *22 using configuration "^/bin"
2014/03/31 16:16:31 [debug] 32244#0: *22 http cl:-1 max:104857600
2014/03/31 16:16:31 [debug] 32244#0: *22 rewrite phase: 3
2014/03/31 16:16:31 [debug] 32244#0: *22 post rewrite phase: 4
2014/03/31 16:16:31 [debug] 32244#0: *22 generic phase: 5
2014/03/31 16:16:31 [debug] 32244#0: *22 generic phase: 6
2014/03/31 16:16:31 [debug] 32244#0: *22 generic phase: 7
2014/03/31 16:16:31 [debug] 32244#0: *22 access phase: 8
2014/03/31 16:16:31 [debug] 32244#0: *22 access phase: 9
2014/03/31 16:16:31 [debug] 32244#0: *22 access phase: 10
2014/03/31 16:16:31 [debug] 32244#0: *22 post access phase: 11
2014/03/31 16:16:31 [debug] 32244#0: *22 try files phase: 12
2014/03/31 16:16:31 [debug] 32244#0: *22 http script var: "/bin/save"
2014/03/31 16:16:31 [debug] 32244#0: *22 trying to use file: "/bin/save" "/mnt/foswiki/Foswiki-1.1.9/bin/save"
2014/03/31 16:16:31 [debug] 32244#0: *22 try file uri: "/bin/save"
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 13
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 14
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 15
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 16
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 17
2014/03/31 16:16:31 [debug] 32244#0: *22 content phase: 18
2014/03/31 16:16:31 [debug] 32244#0: *22 http filename: "/mnt/foswiki/Foswiki-1.1.9/bin/save"
2014/03/31 16:16:31 [debug] 32244#0: *22 add cleanup: 00000000008C3B50
2014/03/31 16:16:31 [debug] 32244#0: *22 http static fd: 15
2014/03/31 16:16:31 [debug] 32244#0: *22 http set discard body
2014/03/31 16:16:31 [debug] 32244#0: *22 xslt filter header
2014/03/31 16:16:31 [debug] 32244#0: *22 HTTP/1.1 200 OK

The try_files directive under the /bin location evaluates $uri first, and if the file is not found passes the request to the @foswiki named location where the fastcgi params are. This works great for views because /bin/view/Web/Topic does not exist on the server, so @foswiki is always called. For /bin/edit and /bin/save this is also true, unless there is a POST. In this case the request is directly to the script which causes Nginx to skip the @foswiki block and attempt to serve the script as a static page. When this happens, one of two things result. A POST to a static page is treated as an error and a 405 is returned to the browser. This was my first problem. With the redirect after request validation there is no 405 error even though there is a POST (not sure why), so we just get the script back as a static page.

With some digging around, I have managed to find a solution. Instead of,

  location ~ ^/bin {
    try_files $uri @foswiki;
  }

I am using,

location ~ ^/bin {
error_page 403 = @foswiki;
return 403;
}

It's the only way to get Nginx to go through a named location, always. Since /bin doesn't contain any static files, this seems appropriate. And supposedly error_page is more efficient than try_files for redirects anyway.


Best,
Chris


On Tue, Apr 1, 2014 at 1:26 AM, Michael Daum <[hidden email]> wrote:
Hi Chris,

have a look at http://foswiki.org/Support/FoswikiOnNginx
I've attached my setup at the bottom of the page. So far everything works all fine.
Maybe there is something in there that helps you sorting out the issue that you have.

Michael.

On Monday 31 March 2014 12:01:25 Chris Hoefler wrote:
> Hi,
>
> We are attempting to use Foswiki with Nginx. I followed the instructions in,
> http://foswiki.org/Extensions/FastCGIEngineContrib
>
> to set up a proper nginx.conf file with the foswiki.fcgi process running in
> the background. The instructions were fine except for one problem. Logging
> in and viewing topics worked, but saving topics returned a 405 error.
> Editing one of the location settings fixed the problem,
>
>         location ~ ^/bin {
>                 try_files $uri @foswiki;
>                 error_page 405 = @foswiki;
>         }
>
> Now, everything seems to work well...except request validation. When a
> request validation is necessary, the server does not seem to do a proper
> hand off to the fastcgi backend. I get the following returned from the
> server,
>
> #! /usr/bin/perl -wT # See bottom of file for license and copyright
> information use strict; use warnings; BEGIN { if ( defined
> $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { $Foswiki::cfg{Engine}
> = 'Foswiki::Engine::CGI'; use CGI::Carp qw(fatalsToBrowser); $SIG{__DIE__}
> = \&CGI::Carp::confess; } else { $Foswiki::cfg{Engine} =
> 'Foswiki::Engine::CLI'; require Carp; $SIG{__DIE__} = \&Carp::confess; }
> $ENV{FOSWIKI_ACTION} = 'save'; @INC = ( '.', grep { $_ ne '.' } @INC );
> require 'setlib.cfg'; } use Foswiki (); use Foswiki::UI ();
> $Foswiki::engine->run(); __END__ Foswiki - The Free and Open Source Wiki,
> http://foswiki.org/ Copyright (C) 2008-2010 Foswiki Contributors. Foswiki
> Contributors are listed in the AUTHORS file in the root of this
> distribution. NOTE: Please extend that file, not this notice. Additional
> copyrights apply to some or all of the code in this file as follows:
> Copyright (C) 1999-2007 Peter Thoeny, [hidden email] and TWiki
> Contributors. All Rights Reserved. TWiki Contributors are listed in the
> AUTHORS file in the root of this distribution. This program is free
> software; you can redistribute it and/or modify it under the terms of the
> GNU General Public License as published by the Free Software Foundation;
> either version 2 of the License, or (at your option) any later version. For
> more details read LICENSE in the root of this distribution. This program is
> distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
> without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE. As per the GPL, removal of this notice is prohibited.
>
> Does anybody have any insight into how to go about fixing this? As far as I
> can tell from the location rules, the request should be processed through
> the @foswiki block. My @foswiki block looks like this,
>
>         location @foswiki {
>                 gzip off;
>
>                 fastcgi_pass 127.0.0.1:9000;
>                 fastcgi_split_path_info  ^/bin/(.+?)(/.*)$;
>                 fastcgi_param SCRIPT_FILENAME
> /mnt/foswiki/Foswiki-1.1.9/bin/foswiki.fcgi;
>                 fastcgi_param PATH_INFO $fastcgi_path_info;
>
>                 include fastcgi_params;
>         }
>
>
> Thanks,
> Chris


--
-- Michael Daum Consulting
-- Wissensmanagement und Intranet-Technologie
-- http://michaeldaumconsulting.com
-- Tel: <a href="tel:%2B49%20%280%2940%2021%2099%2027%2051" value="+494021992751">+49 (0)40 21 99 27 51



--
Chris Hoefler, PhD
Postdoctoral Research Associate
Straight Lab
Texas A&M University
2128 TAMU
College Station, TX 77843-2128

------------------------------------------------------------------------------

_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss