Ruby on Rails

From SilverRack - Affordable VPS Hosting - Wiki

Jump to: navigation, search

Sample Apache Config

Here's a sample Apache vhost entry for using Ruby on Rails and Mongrel Cluster:

NameVirtualHost *:80

<Proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:5000
  BalancerMember http://127.0.0.1:5001
</Proxy>

<VirtualHost *:80>
  ServerName myserver.com
  DocumentRoot /var/www/myserver.com/current/public
  <Directory "/var/www/myserver.com/current/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /maintenance.html [L]
  RewriteRule ^/$ /index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
  AddOutputFilterByType DEFLATE text/html text/plain text/xml
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  ErrorLog logs/myserver_error_log
  CustomLog logs/myserver_access_log combined
  ProxyTimeout 600
</VirtualHost>

Add PHP Support to Apache and Mongrel

Add these lines to your vhost's conf file:

 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} \.php
 RewriteRule ^(.*)$ $1 [QSA,L]
 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
 RewriteRule ^(.*)$ $1/index.php [QSA,L]