5

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.

Community
  • 1
  • 1
tatlar
  • 3,080
  • 2
  • 29
  • 40
  • It has been recommended to me that since everything is on the same server I should probably be using mod_rewrite rather than mod_proxy. – tatlar Sep 27 '12 at 23:12

1 Answers1

3

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.

tatlar
  • 3,080
  • 2
  • 29
  • 40
  • This did not completely solve the problem. The Django **get_absolute_url** method is not always working and occasionally leaves the port number (8000) in the links it generates. – tatlar Sep 28 '12 at 17:20
  • 100% fixed by removing **get_absolute_url()** and replacing with the **{% url "named-view" %}** syntax. – tatlar Apr 17 '13 at 17:28