Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm making a JavaScript web application that will reside in the directory "js" while in development. It will be concatenated into one file and placed in the "static" folder for distribution, but while I'm developing I would like the directory "/js" to point to the JavaScript source which is not located in the "static" folder.

This is my configuration file for nginx, and from what I understand it should work:

# Dev server.
server {
    listen 1337;
    charset UTF-8;

    location /js {
        root /home/tomas/projects/streamcore/js;
    }

    location / {
        root /home/tomas/projects/streamcore/static;
        index index.html;
    }
}

I can access "index.html", but any request to files under "/js" ends up in 404 NOT FOUND. According to the documentation the request should match the location block with the most specific pattern, which in this case is "/js", so I don't see why this isn't working.

Please request additional information if needed. Thanks for any help.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

A couple things!

  1. As per the Nginx pitfalls page, using root inside location blocks might work, but will probably have unintended side-effects. They recommend using 'alias' instead.
  2. The same page also recommends against using index blocks inside locations - instead, use it a single time and it will be inherited to the blocks underneath.

I would change your file, as based on your example, to something like this:

server {
    listen 1337;
    charset UTF-8;

    root /home/tomas/projects/streamcore/static;
    index index.html;

    location /js {
        alias /home/tomas/projects/streamcore/js;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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