Comparing
version 16 and
version 15 backNginx is a proxy/load-balancer that also is able to serve static files (and is a good deal faster at it than mongrel). It's more complicated to setup than pound, but results in a faster setup.
h2. Getting Started
1. ssh in, create a new directory 'nginx' (this can be placed anywhere you like, but for purposes of example I'm putting it in the home directory - /var/www/virtual/example.com/ - your home dirƒctory may look completely different)
2. Create ~/nginx plus two subdirectories ~/nginx/log and ~/nginx/tmp this can be conveniently done with a single command. $ mkdir -p nginx/{tmp,logs}
3. Create a file nginx.conf, placed in ~/etc (create etc if it doesn't exist). Here's a sample nginx.conf (be sure to replace all instances of /var/www/virtual/example.com with the path to your home directory, as well as all port numbers and such as mentioned in the comments):
worker_processes 1;
pid /var/www/virtual/example.com/nginx/tmp/nginx.pid;
# Valid error reporting levels are debug, notice and info
error_log /var/www/virtual/example.com/nginx/logs/error.log debug;
events {
worker_connections 1024;
}
http {
access_log /var/www/virtual/example.com/nginx/logs/access.log;
fastcgi_temp_path /var/www/virtual/example.com/nginx/tmp/fcgi_temp;
client_body_temp_path /var/www/virtual/example.com/nginx/tmp/client_body 1 2;
proxy_temp_path /var/www/virtual/example.com/nginx/tmp/proxy_temp;
include conf/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain text/html text/xhtml text/css text/js;
upstream mongrel {
#### Replace these with the ports for your mongrel cluster:
server 127.0.0.1:10000;
server 127.0.0.1:10001;
}
server {
#### Replace with your nginx/pound port and domain name:
# Example port numbers (for vu2123): (8xxx, 1xxx0, 1xxx1) => (8123, 11230, 11231)
#
listen 127.0.0.1:8100; # 8100 = vu2100
server_name example.com;
#### Replace with the full path to your rails app's public directory:
root /var/www/virtual/example.com/rails/railsapp/public;
index index.html index.htm;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4. [[Running and Stopping Nginx|Start]] nginx