URL routing on Bitnami Google Compute Ruby on Rails - ruby-on-rails

I am attempting to deploy the sample rails app: https://github.com/railstutorial/sample_app_rails_4 to the Google Compute Engine using Bitnami. I have followed the wiki instructions to do so from: https://wiki.bitnami.com/Infrastructure_Stacks/BitNami_Ruby_Stack#How_can_I_deploy_my_Rails_application.3f
But upon attempting to access the url for the site, it still does not direct to the Rails app
as you can see here: http://www.1234-ok-go.com (a domain I have purchased) it simply goes to the base Ruby Stack success page.
Even though I have setup the httpd-vhosts.conf to specifically target the Rails App:
<VirtualHost *:80>
ServerName 1234-ok-go.com
DocumentRoot "/opt/bitnami/apps/myapp/htdocs/public"
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
ServerName 1234-ok-go.com
DocumentRoot "/opt/bitnami/apps/myapp/htdocs/public"
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
</VirtualHost>
How can this issue be alleviated and route the URL to my Rails app?

Bitnami developer here.
After you had created your httpd-vhosts.conf (the one you pasted) file under installdir/apps/myapp/conf/ you have to append this line to /installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf
Include "/installdir/apps/myapp/conf/httpd-vhosts.conf"
And then create this file: /opt/bitnami/apps/myapp/conf/httpd-app.conf to look something like this:
<Directory /installdir/apps/myapp/htdocs/public>
Options +FollowSymLinks
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
PassengerEnabled on
PassengerAppRoot "/installdir/apps/myapp/htdocs"
</Directory>
And finally, restart apache:
<installdir>/ctlscript.sh restart apache

Related

How to create dynamic subdomain rails

How can i create subdomain for each user that registers on my site? For example userone.mysite.com and usertwo.mysite.com.
In php it can be done using apache virtual host, but i can't figure out how to do the same in Ruby on Rails. Here is how it can be done in apache
<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias mysite.com *.mysite.com
DocumentRoot /www/domain
</VirtualHost>
I went through many blogs but couldn't find the solution.
Please Advice.
<VirtualHost *:80>
ServerName mysite.com
ServerAlias *.my_site.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/my_site
<Directory /var/www/html/my_site>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
and do not forgot change cname * entry to your domain in DNS
Addition to Dinesh Saini answer - you also need to update Rails configs accordingly. For example, if you need deep subdomains you should change
config.action_dispatch.tld_length in staging.rb and you should re-check routes.rb.
Live example: I had to implement shop displaying by subdomain - example URL
my-shop.shop.testapp.com.So what I did except server config changes
constraints (lambda { |req| req.subdomains[1] == 'shop' }) do
get '/', to: 'shopes#show', as: :shop
end
In controller to find resource
Shop.find_by(id: request.subdomains[0])
I also set
config.action_dispatch.tld_length = 2
I did this for staging env because it has such URL staging.testapp.com so I need another subdomain level. I think for you it's only good to check that it's has 1.

Rails 3 + passenger conf file

I have been trying to install a rails app on a box that originally was used for multiple php applications. I installed passenger and created a conf file but I am confused about how it all works together.
What should my ServerName be if i want to access a Rails app? The box is a debian squeeze running apache2 with passenger module installed. Below is my conf file. I currently have to go to xxx.xxx.xxx.xxx/leoadmin/public to get the application to run properly. I have the following htaccess in the public directory. Which I think is unnecessary if my conf file is configured correctly.
I think my main issue is the misconfiguration of the conf file. I believe the conf file is being loaded but i don't understand why i still need the htaccess for me to see any action.
.htaccess
#PassengerEnabled On
PassengerAppRoot /var/www/leoadmin/
#Options -MultiViews
#PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#RackBaseURI /var/www/leoadmin
vhost config
<VirtualHost *>
ServerName leoadmin
DocumentRoot /var/www/leoadmin/public
<Directory /var/www/leoadmin/public>
Allow from all
</Directory>
Alias /leoadmin /var/www/leoadmin/public
<Location /leoadmin>
SetEnv RAILS_RELATIVE_URL_ROOT "/leoadmin"
PassengerAppRoot /var/www/leoadmin
</Location>
ErrorLog /var/log/apache2/leoadmin-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/leoadmin-access.log combined
</VirtualHost>
I had nothing but pain and more pain trying to get this sorted a few months back, my configuration allows me to do sub URIs, so I'm not sure if that's what you want, but it'll be along these lines. I've never needed a .htaccess file for this setup:
NameVirtualHost *:80 <VirtualHost *:80>
ServerName www.test.co.uk
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
RailsEnv development
<Directory /web/rails_projects/test/>
Options -MultiViews
</Directory>
For me /web/rails is a root directory, from there I have a number of symlinks to my /home/ directory where I store my projects. ServerName is whatever qualified name you're using for the machine that's going to be recognised.
(just in case, I'm running Passenger 3.0.9, and Rails 3.2.11)

Phusion Passenger + Apache 2 + Rails 3. Works on local network, not when accessed externally

The problem:
I have created a Rails project skeleton using rails new TestApp in the /var/www/ directory of my server. The Rails default index.html displays and works properly (i.e., you see the rails logo and when you click on "About your application's environment" you get a correct listing of the environment specifications used on the server) when I access the site from the same network on which the server is running. However, if I access the site from a machine on a different network than the server's, the page displays but I do not get the rails logo image, and clicking on "About your application's environment" results in the following error display on the page:
Not Found
The requested URL /TestApp/rails/info/properties was not found on this server
And that URL shouldn't be found, because it doesn't exist. However, TestApp/public/rails/info/properties does exist.
Configuration:
The site resides in /var/www/TestApp and I access it from a Sub-URI. I have created a symbolic link in /var/www/ called rails as follows: rails -> /var/www/TestApp/public, such that the project can be accessed from www.mydomain.com/rails. My Apache configuration is the following, note that I've omitted,changed, or shortened some parts within the <VirtualHost> tag for brevity:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ex$
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.mydomain.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
.
.
.
#Rails Configuration
RailsBaseURI /rails
RailsEnv development
PassengerUserSwitching off
PassengerDefaultUser www-data
<Directory /TestApp/public>
Options FollowSymLinks -MultiViews
AllowOverride All
Allow from all
</Directory>
#End Rails Configuration
.
.
.
</VirtualHost>
A couple of things: the appropriate folders are owned by www-data with the appropriate permissions as defined by the Passenger documentation. When setting up the symlink and RailsBaseURI settings I followed the Passenger documentation.
I guess I'm at a loss here since everything seems to be working when accessing the website from the same network on which the server resides. I'm not sure why things aren't working out when accessing the site from a different network, but I feel like paths to certain resources/assets (like the rails logo) aren't resolving properly. Perhaps my symlink is configured inappropriately, or something is wrong with my Apache configuration?
Any help would be appreciated.
The issue of a somewhat broken default Rails page is not totally abnormal, it turns out.
I removed the default Rails page and replaced with another page that included some Rails code and everything worked like a charm.

Passenger: RailsBaseURI case sensitive?

I used Passenger to deploy a RoR app to a sub URI on my domain. The problem I'm facing is that the sub URI seems to be case sensitive. Navigating to http://mydomain.com/RailsApp resolves fine. However, if I go to http://mydomain.com/railsapp, http://mydomain.com/railsApp, or any other variation, I get a 404 error. How can these requests using different casings get resolved correctly?
Here is my Apache configuration file:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /www/mydomain/public
<Directory "/www/mydomain/public">
RailsEnv "production"
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /RailsApp
<Directory "/www/RailsApp/public">
RailsEnv "development"
Options -MultiViews
</Directory>
</VirtualHost>
Any help is much appreciated. Thanks!
You could look into using mod_rewrite and matching it case insensitive there.
Some links to get you started :)
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
Thanks ba for pointing me in the right direction.
I did some research and found the mod_speling module. This not only makes the URL case-insensitive but also checks for spelling errors.
To enable mod_speling:
sudo /usr/sbin/a2enmod speling
sudo /etc/init.d/apache2 force-reload
sudo /etc/init.d/apache2 restart
To use mod_speling, include the directive CheckSpelling on in your virtual host section:
<VirtualHost *:80>
CheckSpelling on
...
</VirtualHost>

Controller pages inaccessible in new RoR project...why?

I set up a new RoR project on MAC OS Leopard, created a repository, svn added the whole Rails project, committed, checked out at my site, set up a vhost (see below), and I cannot get to a new controller page I created (/mycontroller/index). I CAN get to the "Welcome Aboard" page. I have another Ruby install (Redmine project management software) running with Apache.
I get this:
Not Found
The requested URL /developer was not found on this server.
Apache/2.2.8 (Ubuntu) mod_fastcgi/2.4.6 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch mod_scgi/1.12 Server at colorubooks.chadjohnson.ath.cx Port 8080
Here is my vhost setting:
<VirtualHost *:80>
ServerName mysite.mydomain.ath.cx
ServerAdmin email#gmail.com
DocumentRoot /srv/www/mysite.mydomain.ath.cx/public
RailsEnv development
<Directory "/srv/www/mysite.mydomain.ath.cx/public">
Options Indexes ExecCGI FollowSymLinks -MultiViews
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
First:
In DocumentRoot you missed a /
change:
DocumentRoot /srv/www/mysite.mydomain.ath.cxpublic
to:
DocumentRoot /srv/www/mysite.mydomain.ath.cx/public
then you should be able to see static files in the /public directory (like the welcome aboard page)
Now I have a question for you... I presume that you want to use apache to deploy... Have you already installed and setup passenger (mod_rack) apache module?
Link to easy passenger install guide: http://modrails.com/install.html
enjoy!

Resources