WebFaction
Community site: login faq

If you install MoinMoin to serve from a location somewhere other than the root (say /wiki), and correctly configure the url_prefix in moin.wsgi, MoinMoin stil thinks it running at the root, and will not serve pages correctly.

asked 04 Dec '11, 20:19

MikeyP
111
accept rate: 0%


I seems the wsgi application in not passed the correct path in SCRIPT_NAME.

I found two changes were needed. The examples below are for /wiki as the url prefix

1) in wikiconfig.py, specify the path normally in url_prefix_static:

# The URL prefix we use to access the static stuff (img, css, js).
# Note: moin runs a static file server at url_prefix_static path (relative
# to the script url).
# If you run your wiki script at the root of your site (/), just do NOT
# use this setting and it will automatically work.
# If you run your wiki script at /mywiki, you need to use this:
url_prefix_static = '/wiki' + url_prefix_static

2) in moin.wsgi, add a piece of WSGI middleware to add the correct prefix to the SCRIPT_NAME:

from MoinMoin.web.serving import make_application

class AddWSGIPrefix(object):
    """ WSGI Middleware to fudge url prefixes.

    Adds a prefix to all url's passed to the wrapped WSGI application.  
    This is needed for MoinMoin running on Webfaction at a sub-url 
    such as /wiki, since the webFaction configuration uses a proxy in 
    front of Apache/WGI.  The result is a WebFaction app at, say, /wiki,
    receives a WSGI script_name of /, rather than /wiki

    Note, the type of SCRIPT_NAME is native in Python 2.X, but possibly
    Unicode in Python 23x  See http://www.wsgi.org/en/latest/python3.html

    """

    url_prefix = '/wiki'

    def __init__(self,application):
        self._application = application

    def __call__(self, environ, start_response):
        """adjust script_prefix, and pass the call along """
        environ['SCRIPT_NAME'] = self.url_prefix + environ['SCRIPT_NAME']
        return (self._application(environ, start_response))

# Creating the WSGI application
# use shared=True to have moin serve the builtin static docs
# use shared=False to not have moin serve static docs
# use shared='/my/path/to/htdocs' to serve static docs from that path

application = make_application(shared=True)

# wrap the original application with the prefix middleware

application = AddWSGIPrefix(application)
permanent link

answered 04 Dec '11, 20:27

MikeyP
111
accept rate: 0%

1

I created an account on this forum so that I could give you the appropriate amount of thanks and praise for this solution. I nearly pissed my day away and was about to see if I could use Apache's mod_rewrite (what a miserable rabbit hole that would have been) when I came upon your answer. Were I only able to give you an upvote...

(09 Mar '12, 02:32) chb
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×62
×6
×1

question asked: 04 Dec '11, 20:19

question was seen: 4,423 times

last updated: 09 Mar '12, 02:33

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM