TWiki on Nginx
Instructions to install TWiki on high performance Nginx webserver (pronounced "Engine-X")
Download and install TWiki
See
TWikiInstallationGuide.
Nginx-specific configuration
Access restriction
You should restrict access to the configuration script and all twiki directories except the bin and pub directories.
The following code is a concrete example.
location ~ ^/twiki/ {
deny all;
location ~ ^/twiki/pub/ { allow all; }
location ~ ^/twiki/bin/configure {
#allow *.*.*.*; # When you configure your TWiki, remove "#" and set your IP address.
fastcgi_pass 127.0.0.1:8999;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ ^/twiki/bin/ {
allow all;
fastcgi_pass 127.0.0.1:8999;
fastcgi_split_path_info ^(/twiki/bin/[^/]+)(/.*)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Enable PATH_INFO
Use fastcgi_split_path_info directive and fastcgi_param directive in order to enable the PATH_INFO environment variable. Refer to above code.
URL shortening
If you edit your LocalSite.cfg and add the following:
$TWiki::cfg{ScriptUrlPaths}{view} = '/twiki';
$TWiki::cfg{ScriptUrlPaths}{edit} = '/twiki/edit';
you should add the following to your nginx.conf:
rewrite ^/twiki/([A-Z].*) /twiki/bin/view/$1;
rewrite ^/twiki/edit/(.*) /twiki/bin/edit/$1;
The entire code is as follows:
location ~ ^/twiki/ {
rewrite ^/twiki/([A-Z].*) /twiki/bin/view/$1;
rewrite ^/twiki/edit/(.*) /twiki/bin/edit/$1;
deny all;
location ~ ^/twiki/pub/ { allow all; }
location ~ ^/twiki/bin/configure {
#allow *.*.*.*; # When you configure your TWiki, remove "#" and set your IP address.
fastcgi_pass 127.0.0.1:8999;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ ^/twiki/bin/ {
allow all;
fastcgi_pass 127.0.0.1:8999;
fastcgi_split_path_info ^(/twiki/bin/[^/]+)(/.*)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This will change your TWiki URLs from:
www.example.com/twiki/bin/view/Main/WebHome to
www.example.com/twiki/Main/WebHome
www.example.com/twiki/bin/edit/Main/WebHome to
www.example.com/twiki/edit/Main/WebHome
References
--
Contributors: KoheiYoshioka - 2012-09-25
Discussion
Thank you very much Kohei-san for documenting the Nginx installation! Yet another useful enhancement for the TWiki community.
I added links in appropriate places to this topic.
--
PeterThoeny - 2012-09-25
Feedback in
KampalaReleaseMeeting2013x10x24 on TWiki on Nginx installation:
- configure nginx.conf with proper server{} section pointing to your http dir;
- move the twiki dir into it;
- installed these modules: local::lib, CGI-Session-4.48, FreezeThaw-0.5001, Time-modules-2013, GD-2.50, Rcs-1.05;
- install fcgi-wrapper and spawn-fcgi.
- create script with case--switch statements to manage launch/reset;
- and login to nginx
BTW, I do not recommend to expose the whole twiki dir as http enabled, this can be a security risk. Only the
twiki/pub needs to be http enabled, and the
twiki/pub CGI enabled.
--
Peter Thoeny - 2013-10-25
Here is another installation instruction:
http://www.bdunk.com/twiki-nginx
--
Peter Thoeny - 2014-01-23
Another sample configuration is at
Support.SID-00831, contributed by
FangXing.
--
Peter Thoeny - 2015-11-09