Erinevus lehekülje "Ruby on rails" redaktsioonide vahel
Allikas: Kuutõrvaja
98. rida: | 98. rida: | ||
start_stop_rails $i $CMD | start_stop_rails $i $CMD | ||
done | done | ||
+ | |||
+ | httpd.conf | ||
+ | |||
+ | kontrollime ,et read oleksid | ||
+ | |||
+ | LoadModule proxy_module libexec/apache22/mod_proxy.so | ||
+ | LoadModule proxy_connect_module libexec/apache22/mod_proxy_connect.so | ||
+ | LoadModule proxy_ftp_module libexec/apache22/mod_proxy_ftp.so | ||
+ | LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so | ||
+ | LoadModule proxy_ajp_module libexec/apache22/mod_proxy_ajp.so | ||
+ | LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so | ||
+ | |||
+ | |||
+ | <VirtualHost 193.40.0.10:80> | ||
+ | ServerName konkurss.eenet.ee | ||
+ | DocumentRoot /home/rails/konkurss | ||
+ | |||
+ | <Directory "/home/rails/konkurss"> | ||
+ | Options FollowSymLinks | ||
+ | AllowOverride None | ||
+ | Order allow,deny | ||
+ | Allow from all | ||
+ | </Directory> | ||
+ | |||
+ | RewriteEngine On | ||
+ | |||
+ | |||
+ | # Redirect all non-static requests to cluster | ||
+ | #RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f | ||
+ | RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] | ||
+ | |||
+ | </VirtualHost> | ||
+ | |||
+ | <Proxy balancer://mongrel_cluster> | ||
+ | BalancerMember http://127.0.0.1:8101 | ||
+ | BalancerMember http://127.0.0.1:8102 | ||
+ | BalancerMember http://127.0.0.1:8103 | ||
+ | </Proxy> | ||
+ | |||
+ | <VirtualHost 193.40.0.10:80> | ||
+ | ServerName koolielu.edu.ee | ||
+ | DocumentRoot /home/www/koolielu | ||
+ | |||
+ | <Directory "/home/www/koolielu/"> | ||
+ | Options FollowSymLinks | ||
+ | AllowOverride None | ||
+ | Order allow,deny | ||
+ | Allow from all | ||
+ | </Directory> | ||
+ | <Directory "/home/rails/admin/public/"> | ||
+ | Options FollowSymLinks | ||
+ | AllowOverride None | ||
+ | Order allow,deny | ||
+ | Allow from all | ||
+ | </Directory> | ||
+ | |||
+ | |||
+ | RewriteEngine On | ||
+ | |||
+ | # Rewrite to trailing slash | ||
+ | RewriteRule ^/admin$ /admin/ [R,L] | ||
+ | |||
+ | # test if this is /admin request | ||
+ | RewriteCond %{REQUEST_URI} ^/admin(/.*) | ||
+ | # strip off /admin and put result in ENV | ||
+ | RewriteRule ^/admin(.*) /admin$1 [E=AdminReq:$1] | ||
+ | |||
+ | RewriteCond /home/rails/admin/public/%{ENV:AdminReq} -f | ||
+ | # serve static files | ||
+ | RewriteRule ^/admin/(.*) /home/rails/admin/public/$1 [L] | ||
+ | # If request is not static, proxy to rails | ||
+ | RewriteRule ^/(admin/.*)$ balancer://mongrel_cluster2/$1 [P,QSA,L] | ||
+ | |||
+ | |||
+ | </VirtualHost> | ||
+ | |||
+ | <Proxy balancer://mongrel_cluster2> | ||
+ | BalancerMember http://127.0.0.1:8001 | ||
+ | BalancerMember http://127.0.0.1:8002 | ||
+ | BalancerMember http://127.0.0.1:8003 | ||
+ | </Proxy> | ||
+ | |||
+ | Listen 8000 | ||
+ | <VirtualHost 193.40.0.10:8000> | ||
+ | <Location /> | ||
+ | SetHandler balancer-manager | ||
+ | Deny from all | ||
+ | Allow from localhost | ||
+ | </Location> | ||
+ | </VirtualHost> |
Redaktsioon: 23. jaanuar 2007, kell 22:33
Apache22 ruby on rails and mongrel
Süsteem toimib nii ,et apache suunab vhostide info mongrel serverile mis siis railsi skripte esilemanab
Installime vajalikud päkitsad
cd /usr/ports/apache22 make install with_proxy_modules=yes
cd /usr/ports/lang/ruby18 make install && make clean
cd /usr/ports/devel/ruby-gems make install && make clean
gem install mongrel gem install rails
Loome vajalikud skriptid
pane rcrails /etc/init.d vms kausta ja start_mongrel iga railsi script kausta. start_mongreli sees määra USER ja GROUP, kellena see server jooksma peaks.
/usr/local/etc/rails.conf või muusse faili (muuda vastavalt rcrails skripti) kirjuta näiteks:
RAILS_SERVERS=" /home/rails/progeadmin/ /home/rails/veebiadmin/ "
start_mongrel
#!/usr/local/bin/bash USER="root" GROUP="wheel" case $1 in start) /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8001 -a 127.0.0.1 -P rails-8001.pid /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8002 -a 127.0.0.1 -P rails-8002.pid /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8003 -a 127.0.0.1 -P rails-8003.pid ;; restart) /usr/local/bin/mongrel_rails restart -P rails-8001.pid /usr/local/bin/mongrel_rails restart -P rails-8002.pid /usr/local/bin/mongrel_rails restart -P rails-8003.pid ;; stop) /usr/local/bin/mongrel_rails stop -P rails-8001.pid /usr/local/bin/mongrel_rails stop -P rails-8002.pid /usr/local/bin/mongrel_rails stop -P rails-8003.pid ;; *) cat <<EOF USAGE: $0 <start|stop|restart> Mongrel places it's pid files in the RAILS_ROOT directory, which must be writable by the calling user. EOF esac
rcrails
#!/usr/local/bin/bash # # This is proxy skript to start-stop mongrel_rails servers # This script can be placed in /etc/init.d or other rc startup directory # and it will pass its first argument to each rails start script. conf="/usr/local/etc/mongrel.conf" if [ -f $conf ] then source $conf fi # function to do actual calling start_stop_rails(){ echo "" echo "Rails directory: $1" cd $1 ./script/start_mongrel $2 } # set CMD to first argument CMD=$1 for i in $RAILS_SERVERS do start_stop_rails $i $CMD done
httpd.conf
kontrollime ,et read oleksid
LoadModule proxy_module libexec/apache22/mod_proxy.so LoadModule proxy_connect_module libexec/apache22/mod_proxy_connect.so LoadModule proxy_ftp_module libexec/apache22/mod_proxy_ftp.so LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so LoadModule proxy_ajp_module libexec/apache22/mod_proxy_ajp.so LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so
<VirtualHost 193.40.0.10:80> ServerName konkurss.eenet.ee DocumentRoot /home/rails/konkurss <Directory "/home/rails/konkurss"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Redirect all non-static requests to cluster #RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] </VirtualHost>
<Proxy balancer://mongrel_cluster> BalancerMember http://127.0.0.1:8101 BalancerMember http://127.0.0.1:8102 BalancerMember http://127.0.0.1:8103 </Proxy>
<VirtualHost 193.40.0.10:80> ServerName koolielu.edu.ee DocumentRoot /home/www/koolielu <Directory "/home/www/koolielu/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <Directory "/home/rails/admin/public/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Rewrite to trailing slash RewriteRule ^/admin$ /admin/ [R,L] # test if this is /admin request RewriteCond %{REQUEST_URI} ^/admin(/.*) # strip off /admin and put result in ENV RewriteRule ^/admin(.*) /admin$1 [E=AdminReq:$1] RewriteCond /home/rails/admin/public/%{ENV:AdminReq} -f # serve static files RewriteRule ^/admin/(.*) /home/rails/admin/public/$1 [L] # If request is not static, proxy to rails RewriteRule ^/(admin/.*)$ balancer://mongrel_cluster2/$1 [P,QSA,L] </VirtualHost>
<Proxy balancer://mongrel_cluster2> BalancerMember http://127.0.0.1:8001 BalancerMember http://127.0.0.1:8002 BalancerMember http://127.0.0.1:8003 </Proxy>
Listen 8000 <VirtualHost 193.40.0.10:8000> <Location /> SetHandler balancer-manager Deny from all Allow from localhost </Location> </VirtualHost>