Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Nginx to serve static content in front of Django local server
    primarykey
    data
    text
    <p>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:</p> <ol> <li>Got Nginx running on my OSX, so the 'welcome to Nginx!' page shows on localhost.</li> <li><p>Changed my /etc/hosts file to add 'testdev.com':</p> <p>127.0.0.1 localhost</p> <p>127.0.0.1 testdev.com</p></li> <li><p>Made /sites-available and /sites-enabled files in /usr/local/src/nginx-1.2.6</p></li> <li><p>My nginx.conf file in /conf is the default plus the include statement: </p> <p>include /usr/local/src/nginx.1.2.6/sites-enabled/testdev.com</p></li> </ol> <p>5.My testdev.com file is in sites-available, with a symlink in /sites-enabled.</p> <pre><code>server { root /&lt;path-to-my-django-project&gt;/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; } } } </code></pre> <p>If I curl the testdev.com, it shows Nginx:</p> <pre><code>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 </code></pre> <p>But if I try to access a static file, nothing:</p> <pre><code>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 </code></pre> <p>All this is based from a Google search, and finding <a href="http://www.peterbe.com/plog/local-django-development-with-nginx" rel="nofollow">this</a>.</p> <p>I added in the </p> <pre><code>listen 8000 </code></pre> <p>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 </p> <pre><code>127.0.1.1 testdev.com </code></pre> <p>In his hosts file, but if i add that, the first curl statement just hangs.</p> <p>What am I doing wrong? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload