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

In my nginx server {} block I have root defined with a path. How can I later reference this path?

This is what I'm trying to accomplish:

server {
    listen 80;
    root /var/www/foosite;

    ...

    include $root/*.ngaccess;
}

Unfortunately using $root doesn't work (because I haven't defined it). Does Nginx provide a way to access the root value?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You want the document_root variable.

share|improve this answer
    
Doing this: root /var/www/foosite/public/; include $document_root.ngaccess; I get the error "nginx: [emerg] open() "/etc/nginx/$document_root/.ngaccess" failed (2: No such file or directory)." $document_root seems like it would be the solution, but have I typed something wrong? According to this post (and others I came across) forum.linode.com/viewtopic.php?t=7898, variables cannot be used in include statements. Which, if true, is unfortunate. –  skyler May 14 '12 at 2:57
    
That implies that nginx is only evaluating the include directive at startup, not for every request (which makes sense), so it seems that what you want to achieve is not possible unfortunately. –  mgorven May 14 '12 at 6:47

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.