0

I just installed nginx using brew and its default config is located at /usr/local/etc/nginx. The server configuration in default conf file is as below (only small portion pasted)

server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
...
}

The location from which the index.html is being served is /usr/local/var/www/. Now, looking at the above configuration, I don't understand how nginx goes to /usr/local/var/www/ to look for default file? Is there a different configuration that directs nginx to look into that folder?

prabodhprakash
  • 3,825
  • 24
  • 48

2 Answers2

2
  1. If a value of the root directive is relative, the full path is composed using the nginx prefix. See that answer for details.
  2. In the nginx Homebrew formula the --prefix is set to the Homebrew prefix:
      --prefix=#{prefix}
  1. The default Homebrew prefix is /usr/local on Intel.
  2. Thus, the root is html/usr/local/html (the nginx prefix + the relative path).
  3. In the nginx Hombebrew formula this location is symlinked to #{HOMEBREW_PREFIX}/var/www, that is, to /usr/local/var/www:
# nginx's docroot is #{prefix}/html, this isn't useful, so we symlink it
# to #{HOMEBREW_PREFIX}/var/www. The reason we symlink instead of patching
# is so the user can redirect it easily to something else if they choose.
un.def
  • 1,200
  • 6
  • 10
-1

Setting it like this root html makes nginx use relative location. The easiest way is to have the root written with the full desired path like this

root /var/www/html;