I am setting up nginx as a sort of static file server. For some reason it is only working when I go to or However, when I go to or it returns a 404 not found. Here is the config file that is located in /etc/nginx/sites-available and linked to /etc/nginx/sites-enabled. I am really stumped as to why it is not working.

Any pointers or tips would be appreciated.

server {
    server_name "";

     location / {
         root /srv/homepage;
         index  index.html;

     location /static/content/ {
         root /srv/static/content;
         index  song.mp3;

  • Could you verify that really returns /srv/homepage/index.html, and that /srv/static/content/song.mp3 really exists? What do the log files say? – Antonis Christofides May 29 '12 at 7:26
  • check your error_log, there should be more detailed error message. – DukeLion May 29 '12 at 9:09

If you look in your error log, you'll see that a request for, nginx will look for /srv/static/content/static/content/another.mp3. This is due to the way that the root directive works in nginx. When using root, nginx will append the request uri path to the given root, so you'll get one /static/content from the root directive, and another from the request. The correct approach is to just set your root to /srv:

location /static/content/ {
  root /srv;
  index song.mp3;

Since all requests handled by this location will start with /static/content, it will only server files out of /srv/static/content.

| improve this answer | |
  • thanks for the answer. I added the setting to get the log files and it was going to /srv/static/content/static/content/another.mp3. The answer you gave works. In the future I might want to move the files on the server and not change the URI. Is there a way to just get the name of the song and then append that to a place on the file system using nginx? – Scoop May 29 '12 at 17:20
  • 1
    If I understand you correctly, you'd want to use an alias in that case. If you moved the files to /srv/blah instead of /srv/static/content, then it'd look like this: location /static/content/ { alias /srv/blah/; }. When using an alias, you'll need to ensure that any trailing / in the location is matched in the alias or nginx will go looking for the wrong files. – kolbyjack May 29 '12 at 17:57
  • Yes. Excellent. alias will work perfectly!! – Scoop May 29 '12 at 18:23

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.