Apache2 Mongrel-Cluster Configuration

$ wget http://apache.justdn.org/httpd/httpd-2.2.4.tar.gz
($ sudo apt-get install apache2 is NOT recommended)

$ sudo gem install mongrel –include-dependencies
$ sudo gem install mongrel_cluster –include-dependencies
$ sudo /usr/sbin/adduser -r mongrel (creating a user for mongrel running)

cd httpd-2.2.4
./configure –prefix=/etc/apache2 –enable-cache –enable-mem-cache \
–enable-deflate –enable-proxy –enable-proxy-html –enable-proxy-balancer \
–enable-rewrite –enable-headers –enable-filecache –enable-ssl \

make
make install

–Note
# Apache and mongrel could work together in two ways, single instance and cluster
# We will describe both of them as follows:

1 — single mongrel instance
–enter your application’s path
$ mongrel_rails start -d -p 8000

–enter your apache2 httpd.conf, usually /etc/apache2 , and add these scripts

<virtualhost></virtualhost>
ServerName localhost
ServerAlias http://localhost

ProxyPass / http://localhost:8000/
ProxyPass /images !
ProxyPass /stylesheets !
#continue with other static files that should be served by apache

#continue with aliases for static content

ProxyPassReverse / http://localhost:8000/
ProxyPreserveHost on
2 — mongrel cluster
$ sudo gem install daemons gem_plugin mongrel mongrel_cluster –include-dependencies
$ sudo /usr/sbin/adduser -r mongrel

$ cd /path/to/yourapps
$ sudo mongrel_rails cluster::configure -e production \
-p 8000 -N 3

[NOTE! please make sure there’re only one mongrel_cluster.yml file in your system.]

You could test now:
—————
$ sudo mongrel_rails cluster::start
$ sudo mongrel_rails cluster::stop
—————

$ sudo mkdir /etc/mongrel_cluster
$ sudo ln -s /path/to/yourapp/config/mongrel_cluster.yml \
/etc/mongrel_cluster/yourapp.yml
$ cd /etc/init.d/
$ sudo cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster mongrel_cluster
$ sudo chmod +x /etc/init.d/mongrel_cluster

make sure these configuration is uncommented in httpd.conf
NOTE, if you have these modules buit-in, you may ignore it.
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so

DocumentRoot /path/to/yourapp/public

Edit httpd.conf:

<proxy></proxy> BalancerMember http://localhost:8000
BalancerMember http://localhost:8001
BalancerMember http://localhost:8002<virtualhost></virtualhost>
ServerName yourapp.com
ServerAlias http://yourapp.com
ServerAdmin [email protected]

 

DocumentRoot “/path/to/yourapp/public”
RewriteEngine On

ProxyPass /images balancer://yourCluster/images

ProxyPass /stylesheets balancer://yourCluster/stysheets
ProxyPass /javascripts balancer://yourCluster/javascripts

ProxyPass / balancer://yourCluster/

ProxyPassReverse / balancer://yourCluster/
ProxyPreserveHost on

你可能感兴趣的:(apache,html,cache,Ruby,Rails)