downloaded from here
documentation here
If you want to try different solution check it haproxy compiled with: ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --user=mongrel make make install
with fair balancing
Fair load balancing for nginx from here
./configure --with-http_ssl_module --user=mongre --add-module=/usr/local/src/gnosek-nginx-upstream-fair --prefix=/usr/local/nginx --error-log-path=/var/log --http-log-path=/var/log make && make install
base configuration from here
more and my favorite here is good overview of example config
init script from here
http://haproxy.1wt.eu/ is alternative for the nginx
I have one mongrel cluster which is serving multiple rails applications. In my example I host http://system3.spider.bg and http://www.psspy.se in one mongrel cluster. here are the conf files:
# cat nginx.conf user mongrel mongrel; worker_processes 2; #error_log logs/error.log; error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { #worker_connections 16385; worker_connections 1024; } http { default_type application/octet-stream; include mime.types; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; gzip_proxied any; # gzip_http_version 1.1; # gzip_comp_level 1; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; upstream truckhandboken_proxy { server 127.0.0.1:8000; server 127.0.0.1:8001; } upstream system3_proxy { server 127.0.0.1:8200; server 127.0.0.1:8201; server 127.0.0.1:8202; server 127.0.0.1:8203; server 127.0.0.1:8204; server 127.0.0.1:8205; server 127.0.0.1:8206; server 127.0.0.1:8207; server 127.0.0.1:8208; server 127.0.0.1:8209; } include vhosts/*.conf; server { listen 80; server_name localhost:80; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
The virtual host file
# cat system3.conf server { listen 80; #listen 192.168.1.1; #listen 192.168.1.1:8080; server_name system3.spider.bg www.system3.spider.bg; access_log logs/system3.access.log main; location / { proxy_pass http://system3_proxy; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } server { listen 80; #listen 192.168.1.1; #listen 192.168.1.1:8080; server_name *.psspy.se psspy.se; root /home/mongrel/system3/current/public; access_log logs/psspy_access.log main; # Set the max size for file uploads to 50Mb client_max_body_size 50M; # this rewrites all the requests to the maintenance.html # page if it exists in the doc root. This is for capistrano's # disable web task if (-f $document_root/system/maintenance.html) { rewrite ^(.*)$ /system/maintenance.html last; break; } location = / { if (-f /index.html){ rewrite (.*) /index.html last; } proxy_pass http://system3_proxy/dagensps; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; # If the file exists as a static file serve it directly without # running all the other rewite tests on it if (-f $request_filename) { break; } # check for index.html for directory index # if its there on the filesystem then rewite # the url to add /index.html to the end of it # and then break to send it to the next config rules. if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } # this is the meat of the rails page caching config # it adds .html to the end of the url and then checks # the filesystem for that file. If it exists, then we # rewite the url to have explicit .html on the end # and then send it on its way to the next config rule. # if there is no file on the fs then it sets all the # necessary headers and proxies to our upstream mongrels if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://system3_proxy; break; } } # location error_page 500 502 503 504 /500.html; location = /500.html { root /home/mongrel/system3/current/public/500.html; } error_page 404 /404.html; location = /404.html { root /home/mongrel/system3/current/public/404.html; } }# server Good text: http://rubypond.com/articles/2008/02/01/setting-up-nginx-ssl-and-virtual-hosts/ There is generartor gem nginx_config_generator example scripts: http://topfunky.net/svn/shovel/nginx/ nginx connects directly to memcached for caching for restarting nice you might want to see seesaw gem (presentation here) or this blog