Before deploying the rails application for the first time, you need to do the following
1 - Comment out the bitnami default include path and use httpd-vhosts.conf instead
#Include "/opt/rubystack-1.9.3-25/apache2/conf/bitnami/bitnami.conf" Include "/opt/rubystack-1.9.3-25/apache2/conf/extra/httpd-vhosts.conf"
#Include "/opt/rubystack-1.9.3-25/apache2/conf/bitnami/bitnami.conf" Include "/opt/rubystack-1.9.3-25/apache2/conf/extra/httpd-vhosts.conf"
2 - chomd 775 your project directory
How to configure Apache with Phusion Passenger
Make sure you have the Phussion Passenger enabled. Check if the following line is uncommented in Apache config file /installdir/apache2/con/httpd.conf:
Include conf/bitnami/passenger.conf
Assuming you have your application running in /application location, substitute the content of the file /installdir/apps/application/conf/application.conf with the following:
<VirtualHost *:80>
PassengerEnabled on
RailsBaseURI /application
<Directory /installdir/apache2/htdocs/application>
Options -MultiViews
</Directory>
</VirtualHost>
Then ssh to your machine and create a symbolic link:
sudo ln -s /installdir/apps/application/public /installdir/apache2/htdocs/application
(You should make sure that the 'public' and 'config' application folders and their parent directories are readable and executable by Apache).
Make sure you have the Phussion Passenger enabled. Check if the following line is uncommented in Apache config file /installdir/apache2/con/httpd.conf:
Include conf/bitnami/passenger.conf
Assuming you have your application running in /application location, substitute the content of the file /installdir/apps/application/conf/application.conf with the following:
<VirtualHost *:80> PassengerEnabled on RailsBaseURI /application <Directory /installdir/apache2/htdocs/application> Options -MultiViews </Directory> </VirtualHost>
Then ssh to your machine and create a symbolic link:
sudo ln -s /installdir/apps/application/public /installdir/apache2/htdocs/application
(You should make sure that the 'public' and 'config' application folders and their parent directories are readable and executable by Apache).
How to change the default URL with Phusion Passenger
Please make sure you have the Phussion Passenger enabled (check the previous section for the details). Then substitute the content of the file /installdir/apps/application/conf/application.conf with the following:
<VirtualHost *:80>
DocumentRoot /installdir/apps/application/public
<Directory /installdir/apps/application/public/>
PassengerEnabled on
Options -MultiViews
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
Enabling Passenger in bitnami
Finally you have to enable passenger fusion in bitnami config file located in /opt/rubystack/apache2/conf/bitnami/passenger.conf
LoadModule passenger_module /opt/rubystack-1.9.3-25/ruby/lib/ruby/gems/1.9.1/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so
PassengerRoot /opt/rubystack-1.9.3-25/ruby/lib/ruby/gems/1.9.1/gems/passenger-4.0.45
PassengerRuby /opt/rubystack-1.9.3-25/ruby/bin/ruby
PassengerEnabled on
PassengerFriendlyErrorPages off
PassengerUser daemon
PassengerGroup daemon
Restart Apache server:
sudo /installdir/ctlscript.sh restart apache
Please make sure you have the Phussion Passenger enabled (check the previous section for the details). Then substitute the content of the file /installdir/apps/application/conf/application.conf with the following:
<VirtualHost *:80> DocumentRoot /installdir/apps/application/public <Directory /installdir/apps/application/public/> PassengerEnabled on Options -MultiViews <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion> </Directory> </VirtualHost>
Enabling Passenger in bitnami
Finally you have to enable passenger fusion in bitnami config file located in /opt/rubystack/apache2/conf/bitnami/passenger.conf
LoadModule passenger_module /opt/rubystack-1.9.3-25/ruby/lib/ruby/gems/1.9.1/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so PassengerRoot /opt/rubystack-1.9.3-25/ruby/lib/ruby/gems/1.9.1/gems/passenger-4.0.45 PassengerRuby /opt/rubystack-1.9.3-25/ruby/bin/ruby PassengerEnabled on PassengerFriendlyErrorPages off PassengerUser daemon PassengerGroup daemon
Restart Apache server:
sudo /installdir/ctlscript.sh restart apache
Using Apache with Thin
This approach consists on having multiple Thin processes running in different ports. Once they are running, Apache will be set up as a proxy balancer, sending the Rails requests to those ports. It is based in Thin parser, Event Machine and Rack.
On Linux and OS X, you can store the configuration in a yml file and use it to start an stop the group easily. For example:
$ cd your_project_folder $ thin -s 5 -p 3000 -e production --prefix /appname -C config/thin.yml config
Which will configure 5 processes in ports 3000 to 3004, running in a production environment and using prefix /appname. Once the configuration file has been generated, you can start, stop or restart the by running:
$ thin -C ${rails_application_dir}/config/thin.yml start/stop/restart
If you are using Ruby Stack on Windows, you can't start multiple servers using "-s" option. You will need to call a command for each instance:
$ cd your_project_folder $ thin -p 3000 -e production --prefix /appname start thin -p 3001 -e production --prefix /appname start
Regarding Apache, you may include the following lines to apache2/conf/httpd.conf:
ProxyPass /appname balancer://appcluster ProxyPassReverse /appname balancer://appcluster <Proxy balancer://appcluster> BalancerMember http://127.0.0.1:3001/appname BalancerMember http://127.0.0.1:3002/appname ... </Proxy>
Using Apache with Passenger
Note: Before installing Apache and Passenger, make sure to disable (or remove) Nginx if you have it installed; or configure it to not to block Apache's way (i.e. port / socket collisions).Note: If your droplet has less than 1 GB of RAM, you will need to perform the below simple procedure to prepare a SWAP disk space to be used as a temporary data holder (i.e. RAM substitute) for Passenger. Since DigitalOcean virtual servers come with fast SSD disks, this does not really constitute an issue whilst performing the server application installation tasks.
# Create a 1024 MB SWAP space # The process should complete within less than a minute sudo dd if=/dev/zero of=/swap bs=1M count=1024 sudo mkswap /swap sudo swapon /swap
Passenger is only available for OS X and Linux. To use this method, you just need to include a virtual host which DocumentRoot points to 'public' directory in Rails application.<VirtualHost *:80> ServerName myapplication.com DocumentRoot your_project_folder/public <Directory your_project_folder/public> Options -MultiViews <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion> </Directory> </VirtualHost>
No comments:
Post a Comment