I actually have my doubts that mod_wsgi
is leaking. My guess is that your Django
app is leaking. I have personally never found any evidence of mod_wsgi
leaking memory and I run half a dozen mod_wsgi
servers.
Django however is a different story. It's a huge project and in some modules there will be some memory leaked. But most (all?) of the known problems have been fixed in Django 1.1+
.
So... I am guessing that something in your script is leaking. Are you running any specific code that could cause problems? What kind of test are you running exactly? A full site test with something like siege
? Or a simple test on 1 page with ab
?
Regardless, please show the code you are running and/or test if you still have memory leaks with something as simple as this:
def hello_world(request):
return HttpResponse('Hello World!', mimetype='text/plain')
The way I solved this problem is to have nginx reverse proxy all of the sites, but have them go to different apache virtual hosts listening on different ports.
nginx (in /etc/nginx)
proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k; proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
/etc/nginx/sites-enabled/default
server {
listen 80;
server_name django-site.com;
location / {
proxy_pass http://127.0.0.1:8085;
include /etc/nginx/proxy.conf;
}
}
server {
listen 80;
server_name regular-site.com;
location / {
proxy_pass http://127.0.0.1:8086;
include /etc/nginx/proxy.conf;
}
}
Apache Settings /etc/apache2/sites-enabled
django-site
NameVirtualHost 127.0.0.1:8085
<VirtualHost 127.0.0.1:8085>
ServerName django-site.com
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root
PythonDebug On
PythonPath "['/django/django-site'] + sys.path"
</Location>
</VirtualHost>
regular-site
NameVirtualHost 127.0.0.1:8086
<VirtualHost 127.0.0.1:8086>
ServerName regular-site.com
ServerAlias regular-site.com
ServerAdmin admin@regularsite.com
DocumentRoot /var/www/regular-site/
</VirtualHost>
In /etc/apache2/apache2.conf
# Include ports listing
Include /etc/apache2/ports.conf
ports.conf must list every port
/etc/apache2/ports.conf
#Listen 80
#disabled for nginx
Listen 8085
Listen 8086
<IfModule mod_ssl.c>
Listen 443
</IfModule>
Best Answer
Can you tell me what you have done till now. You have to install nginx and set up apache as a reverse proxy. You need to change the port apache listens on to 8080, and nginx will listen to port 80.
The request for static media will be delivered from disk directly, and the other files will be redirected to port 8080 to apache.
If you can ask some more specific questions I can help you with them.
Check out Nginx solution for Apache ProxyPassReverse for an example on reverse proxy. For a more detailed example you can just ask and I will post it.
Better: Using Nginx as a Reverse Proxy to Get the Most Out of Your VPS
Part of my nginx.conf for a subdomain looks like this:
This listen to port 80 for domain.nl and www.domain.nl. When a request is recieved for non-static files the request is passed to port 8080 http://www.domain.nl:8080$request_ur.
When a request for static files is found jpg etc. This is given directly from disk /var/www/vhosts/domain.nl/httpdocs, the location where my website is stored.