First time deploying rails app, cant get passenger to work? - ruby-on-rails

Used railsready, then passenger w/ apache2, finally copied my app to /home/myapp.
Inserted the passenger config lines into /etc/apache2/apache.conf at the bottom along with my virtual host settings:
The servers name is rails.
LoadModule passenger_module /home/myapp/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/myapp/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby /home/myapp/.rvm/wrappers/ruby-1.9.2-p180/ruby
<VirtualHost *:80>
ServerName rails
DocumentRoot /home/myapp/public
</VirtualHost>
All I get is the apache "It Works" page when I open the IP address. Am I doing something wrong?

You declared a ServerName so you must use it to access this VirtualHost (and not the IP address as you mentioned). Connect to http://rails/
For this to work, the hostname rails must resolv to your server's IP. You can add it to you hosts file or use a real domain name configured to resolve to this IP.
Or you can change the DocumentRoot of the default VirtualHost of Apache, and then it will always respond with the Rails app.

Try:
<VirtualHost *:80>
ServerName rails
DocumentRoot /home/myapp/public
<Directory /var/www/robox/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Also, you might need to disable the default site. In Ubuntu you can do this with:
[sudo] a2dissite default
[sudo] service apache2 restart

Related

Deploy ruby on rails app with passenger and apache

I want to deploy my ruby on rails application on Red Hat Enterprise Linux Server release 6.5 server
I have done the following:
Server version: Apache/2.2.15 (Unix)
rvm install ruby
gem install rails
gem install passenger
passenger-install-apache2-module
then I added the following line on my httpd.conf file
LoadModule passenger_module /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50
PassengerDefaultRuby /home/myname/.rvm/gems/ruby-2.1.2/wrappers/ruby
</IfModule>
alos I added the following to my httpd.conf
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# 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>
Additional info
rvm 1.25.31
I restarted the httpd and I cannot see my app running on whatever.com
I have bought the domain and redirected it to the IP of my machine.
What is wrong?
There's a number of reasons why this can happen, #user1876128 had some internal network issues and it wasn't acutally apache at fault.
For this apache setup to work, your network needs to allow http traffic to port 80 of your server box.
It's also advisable to allow traffic on port 3000, so you can run up a rails dev server on the same address (plus :3000) to check any changes before they're up.
You can log in to most domestic routers by pointing your browser at 192.168.0.1 or 192.168.1.1, then using the password (which is either written on your router, or the default password you can find online, or you've already changed it). And setting up a service for port 80 and your server box.
You need to uncomment the line indicated below and restart your apache service (sudo service apache2 restart or similar sudo /etc/init.d/apache2 restart)
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# 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>
This is a common issue with the default stuff from passenger. Chances are you're on a newer version of apache which means # Uncomment this if you're on Apache >= 2.4: would apply.

Properly exposing a Rails server on :80

I have a Rails server (Apache/CentOS-backed) that's accessible at mydomain.com:3000, but I'd like it to be exposed at :80 so I can access it at just mydomain.com. As best I can tell, this should be done through Apache's httpd.conf file. Mine contains the following:
<VirtualHost *:80>
ServerAdmin my-email#gmail.com
#RailsEnv development
DocumentRoot /var/www/webapps/railsSite/public
ServerName mydomain.com
ErrorLog logs/mydomain.com-error_log
CustomLog logs/mydomain.com-access_log common
<directory /var/www/webapps/railsSite/public>
AllowOverride all
Options -MultiViews
</directory>
</VirtualHost>
Am I missing anything from this block?
I'm starting my server via the standard rails server command. I looked up starting it directly to :80 via rvmsudo rails server -p 80, but I get an error saying sudo: rails: command not found. Somehow, sudo's not able to find rails?
Thanks for any help!

Hosting two rails app on single server with same IP

I have a server running a rails 3.2 application. It has thin server running on port 3000, apache(proxy) server running on 443.
Is it possible that if I try to host another rails application on the same server by creating a folder under /www and make it run on port 3002 or any other and then another apache for proxy on some other port ?
The new rails app that I have created is in Rails 4 with Ruby 2.0
Please guide.
Add another VirtualHost for port 3002
<VirtualHost *:3002>
ServerName your-server-name
DocumentRoot /www/your-second-app-public-folder-path
<Directory /www/your-second-app-public-folder-path>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
use host virtual host configuration specifying different ports for the same ip
You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in the "NameVirtualHost" tag, you can allow this to work. If you try using <VirtualHost name:port> without the NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work.
Refer Running different sites on different ports.
Server configuration
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot /www/domain-8080
</VirtualHost>

Mac OSX Lion Apache + RubyOnRails + mod_passenger

I'm trying to learn how to develop web application with Ruby On Rails but I've incurred in a silly error.
I'm trying to use Phusion Passenger aka mod_rails to use Apache instead of WEBrick; I've installed the module via gem and run the
sudo passenger-install-apache2-module
command to install passenger; then I edited the http.conf file adding
LoadModule passenger_module /Users/Stopped/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /Users/Stopped/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19
PassengerRuby /Users/Stopped/.rvm/wrappers/ruby-1.9.3-p327/ruby
added the VirtualHost
<VirtualHost *:80>
ServerName rails.local
DocumentRoot "/Users/Stopped/RoR/prova/public"
<Directory /Users/Stopped/RoR/prova/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restarted Apache with sudo apachectl restart but It's not working :( If I lookup in localhost I see the "It works!" page but if I go at rails.local there is not my Rails app :(
Passenger is loaded
Apache/2.2.22 (Unix) Phusion_Passenger/3.0.19 DAV/2 PHP/5.4.9 Server at localhost Port 80
Any ideas?
PS: This is "apachectl -S" output
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server rails.local (/private/etc/apache2/extra/httpd-vhosts.conf:53)
port 80 namevhost rails.local (/private/etc/apache2/extra/httpd-vhosts.conf:53)
Syntax OK
SOLUTION
Uhm... I solved it, adding 127.0.0.1 rails.local to my hosts file but I can't understand why; can someone explain this to me? ._.
you can't use a wildcard with localhost in your hosts file. you have to explicitly specify each subdomain for localhost in your hosts file. if you're looking for an alternative, you could buy a domain name and point that domain name to 127.0.0.1 with a wildcard. you could even go a step further and have a skeleton app which points different subdomains to different applications by mapping the routes.

Apache: how to config ip address without SeverName?

I want to set my own sever to run my ruby on rails project(with passenger plugin). I use Apache2 on Ubuntu11.04(sever version).
It's my first time to use Apache and I have read some documents.
All the docs ask me to set SeverName,such as Apache doc and ubuntu docs.
Unfortunately, I don't have a domain name, can I just set IP address and use IP address to access this sever?
If it's ok, how should I do?
It's the config sample given by passenger:
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Thanks!
Comment out the line:
# NameVirtualHost *:80
Comment out any <VirtualHost> blocks.
Find the line:
DocumentRoot "/var/www/html" # or whatever your config uses for the overall apache document root.
Change it to your rails application's root.
DocumentRoot "/somewhere/public"
Then add your other config settings to a <Directory> block.
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
I haven't tested this for sure, but you should be able to get to it by only visiting the IP address. Make sure you have Passenger installed, have run passenger-install-apache2-module, and have added the appropriate module loading lines to your apache config.
/etc/apache2/httpd.conf
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/urpc-name/RailsApps/anything/public
<Directory /home/webonise/RailsApps/anything/public>
RailsEnv development
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
In server name:select ur virtual name...u can choose anything
In document root and directory,give your rails project path
Select rails environment in RailsEnv
/etc/hosts
127.0.0.1 example.com
Put server name in virtual host-127.0.0.1 is the localhost
Then just go to your browser and type example.com
Hope this helps

Resources