nginx configuration file explained

Posted by Chris Muench on Server Fault See other posts from Server Fault or by Chris Muench
Published on 2012-09-27T15:00:06Z Indexed on 2012/09/27 15:39 UTC
Read the original article Hit count: 174

Filed under:

I have a few questions about this configuration file "default" in /etc/nginx/sites-enabled. It is shown below.

server 
{
  root /usr/share/nginx/www;
  index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

location / {
    proxy_pass http://127.0.0.1:8080;
}

location /doc {
    root /usr/share;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}

location /images {
    root /usr/share;
    autoindex off;
   }
}
  1. There is no "Listen" directive, how does it know to default to 80
  2. The server_name is localhost, how does another domain work?
  3. Why is the location directive embedded in the server directive? Does that mean these locations ONLY apply to this server?
  4. None of my configs have listen 80 default_server; how does nginx then pick what configuration to use?

© Server Fault or respective owner

Related posts about nginx