Badass Resumes Julep Configuration
When I first switch Badass Resumes to julep and nginx from apache, I expected to spend a few days tweaking the configuration and then I would document the process in a blog post (like this one). Ultimately though, I ended up forgetting about it for several months, during which time it has chugged along with no maintenance whatsoever.
So, I present to you, many months late, the julep and nginx setup that is currently running badass resumes.
The Julep Configuration
The julep configuration is pretty straightforward. The site had previously been running on mod_wsgi, so I just used the existing wsgi file to configure the app. I made the scoreboard available to check on it periodically, though I haven’t ended up using it too much.
from julep import config
from julep import scoreboard
from julep import preload
from wsgiref import simple_server
import logging
logging.basicConfig(level=logging.DEBUG,filename="/var/log/julep/julep.log")
badass_resumes = config.NetworkServer(
address = '127.0.0.1',
port = 5557,
wsgi_file = "/var/www/badassresumes/resumes.wsgi",
access_log = "/var/log/julep/resumes.log",
error_log = "/var/log/julep/resumes.err.log",
preload = [preload.preload_django,]
)
scoreboard_server = config.NetworkServer(
address = '127.0.0.1',
port = 8687,
app = scoreboard.ScoreboardWSGIApplication([
badass_resumes,
])
)
The WSGI File
When I switched from mod_wsgi to julep, I didn’t actually need to change the wsgi file. It is a standard django configuration.
<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">import os,sys</span>
<pre>sys.path.append("/var/www/badassresumes/")
os.environ['DJANGO_SETTINGS_MODULE'] = 'badassresumes.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
The nginx Configuration
The nginx configuration is also pretty simple. The julep instance serving on port 5557 is used as the upstream server that handles the actual requests. Exceptions are made for the media and admin media folders. The final location for handling internal requests is used to support the X-Accel-Redirect header (so that the resumes can be served by nginx rather than being handled by the julep processes).
upstream badass-resumes {
server localhost:5557;
}
server {
listen 80;
server_name badassresumes.com badass-resumes.com;
access_log /var/log/nginx/resumes.access.log;
location / {
proxy_pass http://badass-resumes;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /robots.txt {
alias /var/www/badassresumes/shared/robots.txt;
}
location /admin/media {
alias /var/lib/python-support/python2.5/django/contrib/admin/media;
}
location /media {
alias /var/www/badassresumes/current/files/media;
}
location /var/www/badassresumes/badassresumes/generated/ {
root /;
internal;
}
}
server {
listen 443;
server_name badassresumes.com badass-resumes.com;
access_log /var/log/nginx/resumes-ssl.access.log;
ssl on;
ssl_certificate /etc/nginx/ssl/resumes.crt;
ssl_certificate_key /etc/nginx/ssl/resumes.key;
location / {
proxy_pass http://badass-resumes;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /robots.txt {
alias /var/www/badassresumes/shared/robots.txt;
}
location /admin/media {
alias /var/lib/python-support/python2.5/django/contrib/admin/media;
}
location /media {
alias /var/www/badassresumes/current/files/media;
}
location /var/www/badassresumes/badassresumes/generated/ {
root /;
internal;
}
}
So, any details on how I could use this with Python Paste so that I can try my application out running in Julep?
Jonathan LaCour
February 20, 2010 at 9:12 pm
I haven’t worked with paste before, but I think all you would need to do is import the wsgi app function that you would normally pass to the httpserver and pass it instead to the NetworkServer using the app parameter.
revjohnnyhealey
February 21, 2010 at 4:02 pm