Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would one set the root path of an nginx server to a direcoty outside the ngnix folder?

Currently ngnix is here: c:/ngnix

I would like c:/www to be the root.

currently with server { listen 80; server_name localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
    root  c:/www;
    location / {
        index  index.html index.htm;
        autoindex on;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
share|improve this question
You already have exactly what you want in the piece of config you have pasted there. The only case it won't use c:/www is when the URI /50x.html is triggered as you overwrite the root there. – Martin Fjordvald Jul 27 '11 at 7:59

The root option could be inside the location block. Try:

    location / {
        root   c:/www;
        index  index.html index.htm;
share|improve this answer
Sorry this is not true. Directives should whenever possible be placed in the highest possible context as they inherit down. If placed in location / it is only available in location / not in any other locations. – Martin Fjordvald Jul 27 '11 at 7:58
I was referring to his specific example. In fact, this is the syntax in the example nginx.conf file – I only modified the root line. But you are correct in that his original config works (I tested it just now). – fission Jul 27 '11 at 8:00
In this specific example it makes no sense either. The example nginx.conf file provided with the source install is actually a really bad example and the examples on the nginx wiki should be followed instead. – Martin Fjordvald Jul 27 '11 at 9:10
Interesting – I had no idea! That is good to know, and I'm glad it was captured here as well for posterity. Thanks. – fission Jul 27 '11 at 9:37

Your Answer


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.