Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer

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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.