I'm trying to use Nginx in front of Django's localhost webserver (127.0.0.1:8000) to serve the static content. I'd like Nginx to serve all files under '/static', and if not, pass the request onto the Django's webserver, but I'm stuck! Here's what I've done:
- Got Nginx running on my OSX, so the 'welcome to Nginx!' page shows on localhost.
Changed my /etc/hosts file to add 'testdev.com':
127.0.0.1 localhost
127.0.0.1 testdev.com
Made /sites-available and /sites-enabled files in /usr/local/src/nginx-1.2.6
My nginx.conf file in /conf is the default plus the include statement:
include /usr/local/src/nginx.1.2.6/sites-enabled/testdev.com
5.My testdev.com file is in sites-available, with a symlink in /sites-enabled.
server {
root /<path-to-my-django-project>/website/static;
server_name testdev.com;
gzip off;
listen 8000;
location = /favicon.ico {
rewrite "/favicon.ico" /img/favicon.ico;
}
proxy_set_header Host $host;
location / {
if (-f $request_filename) {
add_header X-Static hit;
access_log off;
}
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8000;
add_header X-Static miss;
}
}
}
If I curl the testdev.com, it shows Nginx:
curl -I http://testdev.com
HTTP/1.1 200 OK
Server: nginx/1.2.6
Date: Mon, 22 Apr 2013 18:37:30 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 21 Apr 2013 19:39:47 GMT
Connection: keep-alive
Accept-Ranges: bytes
But if I try to access a static file, nothing:
curl -I http://testdev.com/static/css/style.css
HTTP/1.1 404 Not Found
Server: nginx/1.2.6
Date: Mon, 22 Apr 2013 18:38:53 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
All this is based from a Google search, and finding this.
I added in the
listen 8000
statement in my testdev.com conf file as I thought that was needed for the Nginx virtual host, but I'm super confused. The blog author used
127.0.1.1 testdev.com
In his hosts file, but if i add that, the first curl statement just hangs.
What am I doing wrong?