Warning!

This guide is LEGACY! Nginx no longer includes a "wsgi_pass" directive, and the mod_wsgi module is no longer available or maintained (if you can find it). You should use the other uwsgi guide instead.

Setting up

You need the NGINX web server compiled with the WSGI module -- refer to those pages for detailed instructions on how to do it, the people on #nginx channel on irc.freenode.net are very helpful, too.

Once you have it running, you need to add this to your nginx.conf file, inside a server block:

        location /moin_static160 {
            alias  /path/to/your/htdocs/directory; # e.g. /usr/share/moin/htdocs
        }

        location / {
             wsgi_pass  /path/to/your/moin.wsgi/file application; # e.g. /var/wiki/moin/moin.wsgi
             include wsgi_params;
        }

Make sure the paths don't include the trailing slash.

Don't forget that the number after moin_static is a MoinMoin version number. For example, for Moin 1.8.2 it will be moin_static182.

In the moin.wsgi file, you need to put the path to your wikiconfig.py file and possibly to the MoinMoin directory, as usual. You may take moin.wsgi from your share directory(see HelpOnInstalling/BasicInstallation): share/moin/server/moin.wsgi.

   1 # -*- coding: utf-8 -*-
   2 # moin.wsgi example
   3 
   4 import sys, os
   5 sys.path.insert(0, '/path/to/your/wiki/instance') # e.g. /var/wiki/moin
   6 
   7 from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp
   8 import wikiconfig
   9 
  10 class Config(WsgiConfig):
  11     pass
  12 
  13 config = Config() # Important!
  14 application = moinmoinApp

The wsgi_params file needs to be present in the configuration directory, and contain this:

wsgi_var  REQUEST_METHOD      $request_method;
#wsgi_var  SCRIPT_NAME         $uri; # TODO
#wsgi_var  PATH_INFO           $uri; # TODO
wsgi_var  QUERY_STRING        $query_string;

wsgi_var  CONTENT_TYPE        $content_type;
wsgi_var  CONTENT_LENGTH      $content_length;

wsgi_var  SERVER_NAME         $server_name;
wsgi_var  SERVER_PORT         $server_port;

wsgi_var  SERVER_PROTOCOL     $server_protocol;

#
# additional variables
# (they will be present in the WSGI environment only if not empty)
#
wsgi_var  REQUEST_URI         $request_uri;
wsgi_var  DOCUMENT_URI        $document_uri;
wsgi_var  DOCUMENT_ROOT       $document_root;

wsgi_var  SERVER_SOFTWARE     $nginx_version;

wsgi_var  REMOTE_ADDR         $remote_addr;
wsgi_var  REMOTE_PORT         $remote_port;
wsgi_var  SERVER_ADDR         $server_addr;


set $auth_type  '';
if ($remote_user) {
    set $auth_type  Basic;
}

wsgi_var REMOTE_USER $remote_user;
wsgi_var AUTH_TYPE   $auth_type;

It is actually the wsgi_vars file that is shipped together with the WSGI module.

That's it. Start the server (or just send a HUP signal to it, to make it reload the configuration) and point your browser to the URL of your new wiki.


CategoryUsabilityObservation

MoinMoin: HowTo/NginxWithModWSGI (last edited 2017-02-12 17:51:54 by swashy)