2

So I'm stymied. I have a webapp that uses Django and I'm using mod_wsgi to integrate it with apache. However, another person has a directive on the same machine that proxies to another server. The apache config is roughly:

My App

WSGIScriptAlias /stuff /foo/foo/wsgi.py
WSGIPythonPath /foo
<Directory /foo/foo>
    <Files wsgi.py>
        Order deny,allow
        Allow from all
    </Files>
</Directory>

His App

<Location "/">
    Order Allow,Deny
    AllowFromAll
    ProxyPass myotherserver
    ProxyPassReverse myotherserver
</Location>

Unfortunately, his Location directive overrides my script directive, and all my requests to http/www.bar.com/stuff end up getting forwarded to http://www.myotherserver.com/stuff without even running through the wsgi script. How do I make requests to /stuff direct to django and not to the proxypass without messing up his code or taking apart his implementation on the other server? I've tried doing

RewriteEngine on
RewriteCond %{REQUEST_URI} ^!/stuff
RewriteRule ^.*$ /bat/$1 [NC,PT]

<Location "/bat">
    Order Allow,Deny
    AllowFromAll
     ProxyPass myotherserver
     ProxyPassReverse myotherserver
</Location>

But this prepends an invalid /bat directory onto my request when it gets to the other server, and breaks all the links on his page. I don't want to go hack all his links.

2 Answers 2

1

So, there were a few issues here. First, looking in the logs on the receiving server told me that all the urls getting forwarded were "/", resulting in all my coworker's pics being broken. This was the result of me capturing the groups in the URI regular expression wrong. Capture the groups by wrapping them in parenthesis.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^!/stuff
RewriteRule ^(.*)$ /bat/$1 [NC,PT]

Now, I did something rather dodgy which works, but I would welcome suggestions as to alternatives.

<Location "/bat">
    Order Allow,Deny
    AllowFromAll
    RewriteRule /bat/(.*)$ $1 [PT]
    ProxyPass myotherserver
    ProxyPassReverse myotherserver
</Location>

So basically, If the incomming request is not my subirectory, I rewrite it so that it has a subdirectory. I pass through to allow it to go through the next location directive. In the location directive for the new subdirectory, /bat, I change it back to what it was and pass it on to the other server so that the address remains intact.

1

I ran into the same issue.

According to this thread, Alias always superseed WSGIScriptAlias.

However, according to modwsgi documentation, it could be replaced by a standard Alias directive. Solution to your issue would be something like below. Note that /stuff is defined before /

Alias /stuff /foo/foo/wsgi.py
WSGIPythonPath /foo
<Directory /foo/foo>
    <Files wsgi.py>
        Options ExecCGI
        SetHandler wsgi-script
        Order deny,allow
        Allow from all
    </Files>
</Directory>

<Location "/">
    Order Allow,Deny
    Allow from all
    ProxyPass myotherserver
    ProxyPassReverse myotherserver
</Location>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .