Here is the full config of my site:

server {
    server_name back.mysite.com;
    access_log /home/django/mysite/deploy/logs/nginx_acc.log;
    error_log /home/django/mysite/deploy/logs/nginx_err.log;

    location / {
        uwsgi_pass      unix:///tmp/uwsgi.sock;
        include         uwsgi_params;

    location /media/sites/ {
      alias /web/mysite.com/sites/;

    location ~ ^/(static|media)/ {
      root /home/django/mysite/mysite;
      expires max;
      log_not_found off;

    location /sites/ {
      root /web/mysite.com;

Now I can open the first link, but can't open the second of the following

http://back.mysite.com/media/sites/files/somefile.jpg #<---can't open but need to

Please, tell me what am I doing wrong.


I would think is a problem with your path.

When you request /media/sites/files/somefile.jpg that alias convert the URL to /web/mysite.com/sites/files/somefile.jpg, so check if the path do exists.

Also check: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

  • Nginx Wiki has better explanation but is still a bit confusing. A request [url] for "/i/top.gif" will instruct Nginx to serve the file [system path] "/spool/w3/images/top.gif". That means that alias directive accepts system file path as an argument, not the url part. – Vlad T. Jan 9 '14 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.