I'm trying to serve Django static media through nginx, Here's my nginx.conf
server {
listen 7777;
listen localhost:7777;
server_name example.com;
location / {
proxy_pass http://localhost:7777;
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;
}
location /test-app-media/ {
root /sites/mysite/staticmedia/;
expires max;
}
}
but give a 502 bad gateway
error, the path to /sites/mysite/staticmedia/
is in the nginx root/ is that the problem..
Django running on Apache 2.2 + mod_wsgi
nginx 0.7.65
Thanks..
if third party app included in your project then it should be installed on your server also like south is third party app. Consider south is included in your settings.py file then south should be installed on your server also. If that module consider south here, is already installed on server then try to upgrade it. Because it is possible that you are using upgraded version of module on local machine and older version is installed in the server.
Unless you're doing unusual things, there's no reason to run both apache and nginx.
Nginx + gunicorn is likely to work better than apache + modwsgi at this point in time.
Gunicorn deployment docs are here:
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/gunicorn/
and the nginx config for deploying that is here:
http://gunicorn-docs.readthedocs.org/en/latest/deploy.html
is because apache has a problem (not restarted or something like that). You can check the apache server logs for info.
The problem is your
/sites/mysite/staticmedia/
is being passed to apache and not served by nginx itself.Your nginx media part has to be like this:
This will access
/sites/mysite/staticmedia/
on the filesystem.That is, the path of location specified with location is a considered to be the part of the file system too. (I don't think this is good way either; but this is how nginx does it.)
You can leave the autoindex on, to help you during debug.
nginx listening on port 7777 and connecting to a proxy located at port 7777 on same host. No wonder it returns 502 error.
the better way would be to use nginx in front of apache and to serve static media:
eg: nginx:
proxy.conf:
nginx.conf:
and configure apache to serve your website on 127.0.0.1:8080
i have this setup on multiple sites and its running perfect. another advantage is, that you can cluster/load-balance your app very easy by adding another apache-server to upstream wwwcluster in nginx.conf