Home Tools

Nginx

Configuring nginx/conf/nginx.conf

the bare minimum necessary for configuration

events {
  worker_connections 1024;
}

http {
  server {
    listen        80;
    server_name   localhost;

    location / {
      # where the website lives on the server
      root /var/www/my-site;

      # name of the default document
      index index.html;
    }
  }
}

configuration block scopes

...
http {
  # configuration at the whole server level

  server {
    # configuration at the site level

    listen        80;
    server_name   localhost;
  }
}

maximum number of connections nginx will support

events {
  worker_connections 1024;
}
...

nginx supports multiple sites listening on the same port, differentiated by domain name

...
http {
  server {
    listen        80;

    server_name   site-a.com;

    location / {
      root /var/www/site-a;
      index index.html;
    }
  }

  server {
    listen        80;

    server_name   site-b.com;

    location / {
      root /var/www/site-b;
      index index.html;
    }
  }
}

Turn on gzip

gzip on;

This reduces the amount of detail sent back in the server header.

server_tokens off;

Adding Headers

add_header X-Frame-Options Deny;
expires 365d;

Commands

Verify that nginx configuration is valid

$ nginx -t

Reload the configuration

$ nginx -s reload

Start the server

$ start nginx

Make sure config.xml and config.ini are not accessible! (don't do this because it will block your xml sitemap)

location ~ \. (xml|ini) {
  deny all;
}