MoinMoin + Nginx

Recently I’ve done quite a lot times of setting up LNMP(Linux + Nginx + Mysql + PHP). During this I notice there’s not much resource on the internet talking about the installation of MoinMoin on Nginx, so here’s what I’ve done to make it run, hope will help. Actually those are collected from other places from internet,

  1. Grab the latest version of spawn-fcgi from http://redmine.lighttpd.net/projects/spawn-fcgi/news and install it.
    tar zxf spawn-fcgi-1.6.3.tar.gz
    cd spawn-fcgi-1.6.3
    ./configure && make && make install
    
  2. Create a script under /etc/init.d/, name it anything you like such as moin-fcgi
    #!/bin/sh
    
    NAME="moin"
    DIR="/srv/share/moin/server"
    FCGIAPP="./moin.fcgi"
    PREFIX="/usr/local"
    
    PORTS="1080"
    
    start_on_port () {
        # Start moin instance on port, leaving pid file
        port=$1
    
        cd "${DIR}" && sudo -u www "${PREFIX}/bin/spawn-fcgi" \
            -f "${FCGIAPP}" \
            -p $port \
            -P "${NAME}-${port}.pid" \
            > /dev/null
    }
    
    kill_on_port () {
        # Try to kill process using pid in pid file, then remove the pid file
        pidFile="${DIR}/${NAME}-$1.pid"
        kill `cat "$pidFile"` && rm -f "$pidFile" > /dev/null
    }
    
    start () {
        for port in $PORTS; do start_on_port $port; done
    }
    
    stop () {
        for port in $PORTS; do kill_on_port $port; done
    }
    
    case "$1" in
    start)
        # XXX starting twice will break pid files (bug in spawn-fcgi)
        start && echo -n " $NAME"
            ;;
    stop)
            stop && echo -n " $NAME"
            ;;
    restart)
        stop
        start && echo -n " $NAME"
            ;;
    *)
            echo "Usage: `basename $0` {start|stop|restart}" >&2
            ;;
    esac
    exit 0
    
  3. Assume we’d like to bind MoinMoin under sub-folder /wiki, modify nginx.conf like this:
    rewrite ^/wiki$ /wiki/;
    location /wiki {
      include fastcgi_params;
      if ($fastcgi_script_name ~ ^/wiki(.*)) {
        set $path_info $1;
      }
      fastcgi_param PATH_INFO $path_info;
      fastcgi_param SCRIPT_NAME /wiki;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
      if (!-f $request_filename) {
        fastcgi_pass 127.0.0.1:1080;
      }
    }
    

    From John Leach

That’s it. For how to install MoinMoin, please check the manual on official website.

About Kymair

A simple guy living in Zhuhai, likes reading, not go out often.
This entry was posted in Web. Bookmark the permalink.

One Response to MoinMoin + Nginx

  1. Scott says:

    Worked for me, with a few mods.

    The moin init.d script above uses FCGIAPP=”./moin.cgi” … typo? Changed to FCGIAPP=”./moin.fcgi” and it works great.

    Also, for wiki hosted at root (on Ubuntu 10.04) I used:
    location / {
    include /etc/nginx/fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param SCRIPT_NAME /;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    if (!-f $request_filename) {
    fastcgi_pass 127.0.0.1:9999;
    }
    }

    Much thanks! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>