Wiki source code of MoinMoin Wiki
Last modified by Sebastian Marsching on 2022/04/03 22:10
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | # Running MoinMoin with Apache’s mod_proxy_fcgi | ||
2 | |||
3 | While MoinMoin works great with mod_fcgid, it does not work with mod_proxy_fcgi out of the box. Luckily, adapting it for mod_proxy_fcgi is not very hard. The `moin.cgi` script included in the MoinMoin distribution is a good starting point. The following script has been derived from the version of this script that is included in MoinMoin 1.9.8. | ||
4 | |||
5 | ```python | ||
6 | #!/usr/bin/python | ||
7 | # -*- coding: iso-8859-1 -*- | ||
8 | """ | ||
9 | MoinMoin - CGI/FCGI Driver script | ||
10 | |||
11 | @copyright: 2000-2005 by Juergen Hermann <jh@web.de>, | ||
12 | 2008 by MoinMoin:ThomasWaldmann, | ||
13 | 2008 by MoinMoin:FlorianKrupicka | ||
14 | 2017 by Sebastian Marsching | ||
15 | @license: GNU GPL, see COPYING for details. | ||
16 | """ | ||
17 | |||
18 | import sys, os | ||
19 | |||
20 | # a) Configuration of Python's code search path | ||
21 | # If you already have set up the PYTHONPATH environment variable for the | ||
22 | # stuff you see below, you don't need to do a1) and a2). | ||
23 | |||
24 | # a1) Path of the directory where the MoinMoin code package is located. | ||
25 | # Needed if you installed with --prefix=PREFIX or you didn't use setup.py. | ||
26 | #sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages') | ||
27 | |||
28 | # a2) Path of the directory where wikiconfig.py / farmconfig.py is located. | ||
29 | # See wiki/config/... for some sample config files. | ||
30 | #sys.path.insert(0, '/etc/moin') | ||
31 | |||
32 | # b) Configuration of moin's logging | ||
33 | # If you have set up MOINLOGGINGCONF environment variable, you don't need this! | ||
34 | # You also don't need this if you are happy with the builtin defaults. | ||
35 | # See wiki/config/logging/... for some sample config files. | ||
36 | #from MoinMoin import log | ||
37 | #log.load_config('/path/to/logging_configuration_file') | ||
38 | |||
39 | # Is fixing the script name and path info needed? | ||
40 | # Use '' if your url looks like http://domain/ | ||
41 | # Use '/mywiki' if your url looks like http://domain/mywiki/ | ||
42 | url_prefix = '/mywiki' # <-- adapt here as needed | ||
43 | |||
44 | from MoinMoin.web.flup_frontend import CGIFrontEnd | ||
45 | |||
46 | class PathFixingCGIFrontEnd(CGIFrontEnd): | ||
47 | def run_server(self, application, options): | ||
48 | from MoinMoin.wikiutil import url_unquote | ||
49 | def prefix_fixer(env, start): | ||
50 | if 'PATH_INFO' not in env: | ||
51 | return | ||
52 | path_info = env['PATH_INFO'] | ||
53 | if path_info.startswith(url_prefix): | ||
54 | path_info = path_info[len(url_prefix):] | ||
55 | path_info = url_unquote(path_info).encode('utf-8') | ||
56 | env['PATH_INFO'] = path_info | ||
57 | if 'SCRIPT_NAME' in env: | ||
58 | env['SCRIPT_NAME'] = url_prefix | ||
59 | # Neither REQUEST_URI nor SCRIPT_FILENAME seem to be used. | ||
60 | return application(env, start) | ||
61 | super(PathFixingCGIFrontEnd, self).run_server(prefix_fixer, options) | ||
62 | |||
63 | PathFixingCGIFrontEnd().run() | ||
64 | ``` | ||
65 | |||
66 | If this script is placed in the same directory as `wikiconfig.py`, you should not have to change any paths. Otherwise, you have to add a `sys.path.insert(...)` line (see the corresponding commented section in the script). | ||
67 | |||
68 | Assuming that you saved the script as `moin-fcgi-server`, you can run start the server using one of the following lines: | ||
69 | |||
70 | ```bash | ||
71 | moin-fcgi-server -i 127.0.0.1 -p 8999 | ||
72 | moin-fcgi-server -i /path/to/fcgi.sock | ||
73 | ``` | ||
74 | |||
75 | The first variant makes the server listen on TCP port 8991 on the loopback interface. Assuming that the wiki is available at [http://example.com/mywiki/](http://example.com/mywiki/), the following line should be added to the respective `VirtualHost` section of the Apache configuration: | ||
76 | |||
77 | ProxyPass "/mywiki" "fcgi://localhost:8999" | ||
78 | |||
79 | When using the second variant, the server listens on a UNIX domain socket and the Apache configuration is slightly different: | ||
80 | |||
81 | ProxyPass "/mywiki" "unix:/path/to/fcgi.sock|fcgi://localhost" | ||
82 | |||
83 | The flup FastCGI server resets the permissions of the socket to match the umask of the process, so permission or ownership changes of the socket are not preserved across restarts. Unfortunately, there is no way to change this without making changes to the MoinMoin code. For this reason, using Unix domain sockets is only feasible when the MoinMoin FastCGI server is running as the same user as the Apache webserver. |