Nginx – Serving static files fails – nginx

djangomod-wsginginxstatic-content

I've been looking and trying around all night, but without success.

I configured nginx to serve my static files and proxy all the other traffic:

server {

    listen 80;
    server_name example.com;

    access_log /home/boudewijn/www/bbt/brouwers/logs/access.log;
    error_log /home/boudewijn/www/bbt/brouwers/logs/error.log;

    location / {
            proxy_pass http://127.0.0.1:8080;
            include /etc/nginx/proxy.conf;
    }

    location /media/ {
            root    /home/boudewijn/www/bbt/brouwers/;
    }
}

The proxy passing is no problem, but when I go to example.com/media/ or try to access any testfile over there, it's without success. I paid attention to the difference between root and alias, my media folder exists, I paid attention to the trailing slashes, but still I get a 404 when trying to access my static media files.

Any help?

Best Answer

I'm assuming your media files are in /home/boudewijn/www/bbt/brouwers/media. In which case the following should work.

If you still get a 404 error then check your error log as it should show you the exact file path it's trying to access.

server {

    listen 80;
    server_name mydomain.com;

    access_log /home/boudewijn/www/bbt/brouwers/logs/access.log;
    error_log /home/boudewijn/www/bbt/brouwers/logs/error.log warn;

    root    /home/boudewijn/www/bbt/brouwers/;

    try_files $uri @proxy;

    location @proxy {
            proxy_pass http://127.0.0.1:8080;
            include /etc/nginx/proxy.conf;
    }
}