Foswiki configuration on Nginx

Foswiki has a plugin for running natively as a FastCGI application. Although at first glance, one may wonder why anyone wouldn't use the native FastCGI plugin, but there are reasons for avoiding the plugin. It turn out that on some low-end systems, the cgi wrapper performs better, also CGI is easier to configure.

Beware: The configure.pl script must be run as CGI even if Foswiki itself runs as a FastCGI application.

  1. start the FastCGI application, you have two ways to do that:
    • Setup the native FastCGI plugin - run the FastCGI script
      cd /var/www/Foswiki/bin; sudo -u www-data ./foswiki.fcgi -n 5 -l /var/run/nginx/foswiki.sock -p /var/run/foswiki.pid -d
      If you use the FastCGI plugin, make sure you set the handler for the configure.pl script to a CGI wrapper, the plugin can't run the configure script.
    • Setup generic fastcgi wrapper with Nginx
  2. configure Nginx location for foswiki
            set $foswiki_root "/var/www/foswiki";
            location /foswiki {
                    root /var/www/foswiki;
                    index index.html; # should be changed after installation
            }
            location /foswiki/bin/configure {
                    allow 127.0.0.1; # localhost, you may want to omit due to security considerations.
                    allow 192.168.12.12; # you management host if you have one
                    deny all;
                    gzip off;
                    fastcgi_pass   unix:/var/run/nginx/perl-cgi.sock;
                    fastcgi_split_path_info ^/foswiki(/bin/configure)(?:\.pl)?(.*);
                    fastcgi_param  SCRIPT_FILENAME  $foswiki_root$fastcgi_script_name;
                    fastcgi_param  PATH_INFO $fastcgi_path_info;
                    include fastcgi_params;
            }
            location /foswiki/bin/ {
                    gzip off;
                    fastcgi_pass   unix:/var/run/nginx/foswiki.sock;
                    fastcgi_split_path_info ^(\w+)(?:\.pl)?(.*);
                    fastcgi_param  SCRIPT_FILENAME  $foswiki_root$fastcgi_script_name;
                    fastcgi_param  PATH_INFO $fastcgi_path_info;
                    fastcgi_param  SCRIPT_NAME  $fastcgi_script_name;
                    fastcgi_param  PATH_TRANSLATED $foswiki_root$fastcgi_path_info;
                    include fastcgi_params;
            }
            location ~ (^/lib|^/data|^/locale|^/templates|^/tools|^/work) {
                    deny all;
            }
            if ($http_user_agent ~ ^SiteSucker|^iGetter|^larbin|^LeechGet|^RealDownload|^Teleport|^Webwhacker|^WebDevil|^Webzip|^Attache|^SiteSnagger|^WX_mail|^EmailCollector|^WhoWhere|^Roverbot|^ActiveAgent|^EmailSiphon|^CrownPeak-HttpAgent|^$) {
                    rewrite .* /404.html break;
            }
    
    
    the fastcgi_split_path_info directive doesn't work in old (0.6*) versions of Nginx, use regex matching with the if ... set directives to split the fastcgi_script_name parameter.
  3. Load the Foswiki configuration wui configure.pl and config your new wiki.
Note: The above configuration works with or without the .pl suffix. A few nice touches:
  • add a redirect to the Main web:
    rewrite ^/foswiki/?$ http://yousite.com/foswiki/bin/view.pl/Main permanent;
  • change $Foswiki::cfg{ScriptSuffix} in foswiki/lib/LocalSite.cfg to an empty string value '' for prettier links.

-- AvishaiIshShalom - 03 Sep 2009
Topic revision: r7 - 26 Mar 2011 - 07:42:41 - AvishaiIshShalom
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback