سؤال

I have a follow up question from my original Django serving question which was how to develop Django apps and serve them from the same server as my main PHP-based site (all part of a larger migration of my website from a static and PHP driven one to a series of Django apps).

I couldn't quite use the name server solution I was provided with, and instead just deployed my Django applications on a different port (8000) using mod_wsgi. Now, however, I need to actually integrate the Django application into the main site. In my Apache 2.0 configuration file (for say http://www.example.com) I added the following ProxyPass commands (after my mod_wsgi initialization):

ProxyPass        /app/newsletter     http://www.example.com:8000/app/newsletter
ProxyPassReverse /app/newsletter     http://www.example.com:8000/app/newsletter

Here I expect that any request to:

http://www.example.com/app/newsletter

will get successfully proxied to:

http://www.example.com:8000/app/newsletter

and all will be right with the world.

However, this is not the case. Apache hangs for 5 or so minutes (the time taken to craft this question) then spits out a 502 Proxy Error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /app/newsletter/.

Reason: Error reading from remote server

Watching my Apache 2.0 error log after this response I see continuous errors like the following:

[Thu Sep 27 15:25:49 2012] [error] Exception KeyError: KeyError(****,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored

So something seems to be remiss in either how mod_proxy plays with Django and/or Python. I have other Java related processes that I use ProxyPass and ProxyPassReverse on and they work fine. Also, when I don't try to apply the ProxyPass the Django apps all work well (ie. when I address them on port 8000 directly).

Any ideas? I don't feel like what I am doing is particularly complex.

Thanks in advance.

هل كانت مفيدة؟

المحلول

In the end, using mod_rewrite was the solution. Added this to Apache's httpd.conf file:

RewriteEngine On
RewriteRule ^/app/newsletter/(.*)$ http://%{SERVER_NAME}:8000%{REQUEST_URI} [P]

Everything works as expected.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top