Nginx

http://del.icio.us/popular/nginx
https://calomel.org/nginx.html

nginx startup script:

#! /bin/sh

# Description: Startup script for nginx webserver on Debian. Place in
/etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command
on your
# distro.
#
# Author:  Ryan Norbauer <ryan.norba...@gmail.com>
# Modified:     Geoffrey Grosenbach http://topfunky.com
# Modified:     David Krmpotic http://davidhq.com

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
  $DAEMON -c $CONFIGFILE || echo -en "\n already running"

}

d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -en "\n not running"

}

d_reload() {
  kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"

}

case "$1" in
  start)
    echo -n "Starting $DESC: $NAME"
    d_start
        echo "."
  ;;
  stop)
    echo -n "Stopping $DESC: $NAME"
    d_stop
        echo "."
  ;;
  reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
        echo "."
  ;;
  restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    # One second might not be time enough for a daemon to stop,
    # if this happens, d_start will fail (and dpkg will break if
    # the package is being upgraded). Change the timeout if needed
    # be, or change d_stop to have start-stop-daemon use --retry.
    # Notice that using --retry slows down the shutdown process
somewhat.
    sleep 1
    d_start
    echo "."
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
  ;;
esac

exit 0

http://groups.google.com/group/rubyonrails-deployment/browse_thread/thread/0ef4939cbf8ab407/4eb93bfe94101ce3?lnk=raot
http://topfunky.net/svn/shovel/nginx/
http://highscalability.com/product-nginx

samples

user www-data;
worker_processes  4; #nice to match your cpu core. good minimal is 2.

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log    /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay        off;

    keepalive_timeout  5 5;

    limit_zone   one  $binary_remote_addr  1m;
    limit_conn   one  5;

    gzip  on;
    gzip_comp_level 9;
# make sure gzip does not lose large gzipped js or css files
# see http://blog.leetsoft.com/2007/7/25/nginx-gzip-ssl
gzip_buffers     16 8k;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Disable gzip for certain browsers. http://zh.stikipad.com/notes/show/nginx
gzip_disable     “MSIE [1-6].(?!.*SV1)”;

    include /etc/nginx/sites-enabled/*;

server {
    listen    80;
    server_name    mypolaris.com ;
    limit_rate  88k;   #limit the rate per connection

if ($server_name == 'www.mypolaris.com' ) {
      rewrite  ^/(.*)$  http://mypolaris.com/$1  permanent;
}
    location / {
        proxy_pass    http://127.0.0.1:81;
        proxy_redirect    off;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
        expires 3h;
        error_page   404          /404.html;
    }

        location ~* ^.+.(png|jpg|jpeg|gif|swf|ico)$ {
                root   /home/web/public_html;
                expires max;

        }
        location ~* ^.+.(htm|html|pdf|css|js)$ {
                root   /home/web/public_html;
                expires 3d;
        }
        location ~ ^/(some|other|stuffs)  {
                root   /home/website/public_html;
                auth_basic            "Restricted";
                auth_basic_user_file  /root/passwd;
        }

} #end server
} #end http

alt nginx.conf: only pass php to apache:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License