lots of tech info here

Configuring Nginx web server

Configuring Nginx

Installing Nginx

This tutorial is specific to Ubuntu Linux, but can be adapted for other versions of *nix and Linux distros. Here, we assume that

Getting started

A typical nginx.conf file looks like this (at least the one on my development machine)

user www-data;
worker_processes  2;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    # turn directory listing off 
    autoindex off;

    # turn on gzip compression
    gzip  on;

    # load all domains
    include /etc/nginx/sites-enabled/*;
}

Brief explanation:

user www-data means Nginx is going to run as user www-data. This is useful if you're making the transition from Apache, where the user is www-data. You won't have to change ownership of any existing files or directories.

You can have a maximum of 2048 clients connected. This number is got by multiplying worker_processes with worker_connections. autoindex is turned off for safety, to prevent visitors from snooping.

gzip is turned on so that Nginx serves compressed web content - save on bandwidth.

The other lines are self-explanatory.

The domain configuration files are located in /etc/nginx/sites-enabled/

Configuring the domain

Suppose we want to use Nginx to host the domain imacster.com this is a basic configuration.

Contents of /etc/nginx/sites-enabled/default

server {
    listen       80;
    server_name  imacster.com;

    # log files
    access_log /etc/nginx/logs/imacstercom/access.log;
    error_log /etc/nginx/logs/imacstercom/error.log warn;

    # directory
    root   /home/username/public_html/imacstercom;
    index  index.html index.php;

    location / {
    }

    error_page   401 403 404      /40x.html;
    error_page   500 502 504      /50x.html;
    error_page   503              @503;
    location @503 {
      rewrite ^(.*)$ /maintenance.html break;
    }
}

That's the basic configuration for Nginx. To include support for PHP scripts, there are 2 ways.

Posted on 01 Jul 2009

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others

Subscribe

Tags