Trying to get my ROR site up and running...getting a 404 - ruby-on-rails

running a R.o.R. site on passenger. Passenger is running fine, but I'm not sure if I am having an issue with the way I setup my vHosts or what, but It's returning a the apache start page, and not my application.
When I run
passenger-status
here is the message:
Version : 4.0.18
Date : 2013-09-26 10:42:03 -0400
Instance: 20958
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
[USERNAME#gregorymurray relaunchradio]#
Here is the passenger stuff in my httpd.conf:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger- 4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
PassengerDefaultUser root
No problem that I see there, here is my vhost.conf file in the main directory of my site:
ServerName gregorymurray.com
ServerAlias gregorymurray.com
DocumentRoot /var/www/vhosts/gregorymurray.com/relaunchradio/public
PassengerAppRoot /var/www/vhosts/gregorymurray.com/relaunchradio
<Directory "/var/www/vhosts/gregorymurray.com/relaunchradio/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsEnv production
RailsBaseURI /
Here are the two links I followed in the process of getting this running:
http://www.twohard.com/blog/setting-rails-passenger-mediatemple-dv35-servers
https://coderwall.com/p/lu3nfa

Are you sure apache2 is finding the vhost.conf file? Are you using some kind of shared hosting that requires placing that file in your website's main directory? Because, that's not the normal setup. The virtual hosts file belongs under /etc/apache2 or /etc/httpd depending on whether using Ubuntu or centOS. Look at your apache conf file to find out where it's looking for the virtual hosts.
Open /etc/httpd/conf/httpd.conf and look for vhost.conf. Or look for a Include directive of the full path to your gregorymurray.com. I doubt either one will be found. Which means you need to move vhost.conf to /etc/httpd/conf/sites-enabled/vhost.conf and add Include sites-enabled/ in your httpd.conf just above the passenger module stuff.
Placing your vhost.conf in your website directory would require that you alter your httpd.conf to look in that website directory for a virtual host conf file. That's not the default setup or conventional setup.

Related

Overwhelmed with Apache mod passenger / Ruby on Rails

i tried to migrate a ruby on rails project from a server to another.
Everything is pretty much working. Now only mod passenger and apache gives me big problems.
Just as a not - i set the following command else i couldnt start apache "a2enmod mod_access_compat"
Now here is my config file:
LoadModule passenger_module /home/homeuser/.rvm/gems/ruby-2.1.10/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/homeuser/.rvm/gems/ruby-2.1.10/gems/passenger-4.0.41
PassengerDefaultRuby /home/homeuser/.rvm/gems/ruby-2.1.10/wrappers/ruby
</IfModule>
ServerAdmin ME
ServerName server.ip
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#DocumentRoot /srv/www/vhosts/default/
DocumentRoot /home/homeuser/projectx/public/
# if not specified, the global error log is used
ErrorLog /var/log/apache2/error_log
CustomLog /var/log/apache2/access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName Off
# configures the footer on server-generated documents
ServerSignature On
#ScriptAlias /cgi-bin/ "/srv/www/vhosts/default/cgi-bin/"
#<Directory "/srv/www/vhosts/default/cgi-bin">
# AllowOverride None
# Options +ExecCGI -Includes
# Order allow,deny
# Allow from all
#</Directory>
<Directory "/home/homeuser/projectx/public/">
#
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Options Multiviews Indexes
RailsEnv development
</Directory>
</VirtualHost>
Now the problem.
On my other server i can just call the IP of the server, and the rails installation just opens fine.
Here is just goes into the "public" directory and indexes me all its contents.
I know a fix where you can alter the routes within the routes config file:
get '/something', to: 'start#index'
Now i can reach the website via browser if i type the adress:
server.ip/something
But like i said - i need a pretty much identical version.
So what i need is being able to reach the site via:
server.ip and not server.ip/something
Any help appreciated. Me and my collegues are going crazy about this :-).
EDIT:As an answer to #Aakash Gupta-
Actually "something" is just any string i set in the routes file so i can enter the webapp via browser. What i want instead is to enter the webapp just by typing the pure IP of the server into the browser. Without the "something". So lets make an example: If i type into the browser: www.website.com - it doesnt work. But if i set a route in the routes file, as shown above, i can enter the site by e.g. www.website/start.com or www.website/whatever.com. But i really dont want to have to type something after the url as it has effects on other stuff. So i just want to type in the pure domain/ server address which would be website.com. And then the webapp should appear - but instead i just get shown the contents of the public folder, as there is no index file inside. But on my other server mod passenger is clever enough to still start the webapp, even if i set the public folder is a document root. Hope that clarifies my problem. Like i said - i didnt have problems on other servers. : /

Ror app not running on CentOS

I am using CentOS 6.6 first time to deploy Rails 4 application. I have installed all necessary softwares like MySQL, Ruby, Rails, Passenger, Apache2, etc. I have tested it for index.html page inside /var/www/html/index.html and set it on Apache configuration and working perfect.
When I deployed Rails application it did run on the server but it displayed as shown in screenshot below.
Below are my Apache configuration settings which I have done so far.
/etc/httpd/conf/httpd.conf
LoadModule passenger_module /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerDefaultRuby /home/user/.rvm/wrappers/ruby-2.1.2/ruby
PassengerRoot /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6
</IfModule>
I have created a file vhost.conf inside /etc/httpd/conf.d/
<VirtualHost *:80>
ServerName myipaddress
DocumentRoot /var/www/html/projectname/public_html/current/public
<Directory /var/www/html/projectname/public_html/current/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>
I run the command below command
service httpd restart
service httpd reload
Neither Rails app running in server nor showing any erros.
Any solution would be appreciated. Thanks in advance.
First and always check the Apache logs. This step is essential, but often overlooked. If that doesn't help, I would try a few things:
Double-check the documentation and make sure you've completely installed Passenger, and haven't skipped a step.
Start by removing the IfModule directive. Since you want Passenger, you want an error message if it isn't loading.
LoadModule passenger_module /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
PassengerDefaultRuby /home/user/.rvm/wrappers/ruby-2.1.2/ruby
PassengerRoot /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6
You have your IP address as your server name. Make sure this doesn't conflict with any other configurations (other sites, or httpd.conf). Otherwise, you may just be loading a different page / application.
Depending on how you have it set up, you may have permissions issues since you're pointing PassengerDefaultRuby and PassengerRoot to /home/user/.rvm. By convention, these are usually somewhere more public like /var/lib/gems/ and /usr/bin/.
Make sure you have defined a root path in your Rails application's config/routes.rb.
Make sure you've chown -R-ed your application path to the apache user. This will help you with troubleshooting and security.
After you've done all that, check the logs again. After you make a change, check the logs again.

Passenger on Apache: "doesn't seem to be running", app page gives 403; what next?

I'm having trouble getting my web server to talk to an app in Ruby on Rails. This is especially frustrating because I had it working last year for several months; I assume that some setting changed in the course of an upgrade in the meantime, but I can't find it.
The symptom: when I navigate to the page that should be serving the app (a sub-URI of the main domain), Apache gives a 403 error: "There is either no index document or the directory is read-protected.". The bottom of this error page gives the config string "Apache/2.4.9 (Unix) OpenSSL/1.0.1g Phusion_Passenger/4.0.37", which seems to indicate that Passenger is loaded and running. If I navigate directly to the public directory, or to the physical directory where the app lives, Apache happily displays the file listing of that directory (and if I click on any of the files, they display), so it doesn't seem to be that kind of permissions problem, at least.
In the httpd.conf file, there were the following lines to load Passenger:
LoadModule passenger_module modules/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.14
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
PassengerEnabled Off
PassengerLogLevel 3
and, later, the following lines to tell Apache about the app:
<Location "/pathtoapp/f13">
Options +Indexes +ExecCGI +FollowSymLinks -MultiViews
Order allow,deny
Require all granted
PassengerEnabled On
RackBaseURI /pathtoapp/f13
#RailsEnv production
RailsEnv development
</Location>
The app itself lives in /pathtoapp/f13app, and there was a symlink in the filesystem from /pathtoapp/f13 to /pathtoapp/f13app/public. If I created a symlink /pathtoapp/test to /pathtoapp/f13app/public, it worked fine (in that it showed a file listing for the public directory, so again, no permissions problems).
I tried changing around a few things based on trawling the net for possible solutions. Most didn't appear to affect anything, so I reverted them; I did note that changing Location to Directory meant that navigating to /pathtoapp/f13 in my browser gave me the file listing of the public directory.
I tried (re-)running sudo passenger-install-apache2-module even though the Apache error seemed to indicate passenger was already installed. It (re-?)installed and prompted some changes to httpd.conf, which now has:
LoadModule passenger_module /usr/lib/ruby/gems/2.1.0/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/gems/2.1.0/gems/passenger-4.0.37
PassengerDefaultRuby /usr/bin/ruby
</IfModule>
(I'm not sure if passenger did the ruby upgrade into /usr/lib or if that came in some earlier system update I'd done, but the indicated files are indeed there.) Later in httpd.conf, based on the current text of http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rack_to_sub_uri , I now have
Alias /pathtoapp/f13 /pathtoapp/f13app/public
<Location "/pathtoapp/f13">
PassengerBaseURI /pathtoapp/f13
PassengerAppRoot /pathtoapp/f13app
PassengerEnabled On
RailsEnv development
</Location>
<Directory "/pathtoapp/f13app/public">
Options +Indexes +ExecCGI +FollowSymLinks -MultiViews
Allow from all
Require all granted
</Directory>
I then removed the in-filesystem symlink from f13 to f13app/public. And, of course, I've restarted httpd.
passenger-status still reports "ERROR: Phusion Passenger doesn't seem to be running.", and navigating to the app's page (/pathtoapp/f13) still gives the same 403 error. I'm now completely stuck as to what to try next, or even what diagnostic tool I should be using to help triage the problem. Any ideas?
(Extra system info: uname -r is "3.14.1-1-ARCH"; apachectl -v is "Apache/2.4.9 (Unix)"; passenger -v is "Phusion Passenger version 4.0.37")
After a lot of mucking about, I finally discovered that the problem was with the Apache configuration itself: Apache was never getting far enough in to even talk to Passenger. Specifically, on the lines
Alias /pathtoapp/f13 /pathtoapp/f13app/public
and
PassengerAppRoot /pathtoapp/f13app
it's important that the pathtoapp be relative to the filesystem, not the URI. So those two lines should really be more like
Alias /pathtoapp/f13 /srv/http/htdoc/pathtoapp/f13app/public
and
PassengerAppRoot /srv/http/htdoc/pathtoapp/f13app
though of course the exact details will vary by system. I'm not sure if this was an issue with Apache 2.2-2.4 upgrade or something else (I have root access but am not the primary sysadmin on this system), but now that I've found the problem, I didn't want to leave the question hanging. I'll also add that the Apache config line
LogLevel debug
was invaluable in helping me track down which system component the problem was in.

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.

Problem deploying Rails with Passenger to Mac OS X Leopard Server

I'm spinning my wheels... Apache is working and serving static html, png, etc. normally. Trying to get Passenger to serve a rails app out of www.mydomain.com/rails/
as it stands when i try to hit my app: www.mydomain.com/rails/myapp/railsclassname
I get only an Apache 403 Errors. Nothing in myapp's Production Log.
Apache2 access.log:
"GET /rails/ HTTP/1.1" 403 1085
Apache2 error.log:
[Fri Jun 11 22:44:01 2010] [error] [client 10.0.1.41] File does not exist: /Library/WebServer/wwwroot/rails/railsclassname
i've even tried www.mydomain.com/myapp/classname
Passenger, obviously, isn't routing requests made into my sub-folder rails/ to my rails app. not sure where i've screwed up. the most obvious thing is "Passenger doesn't seem to be running"... instructions I've followed just say to sudo apachectl graceful, which i've done (as well as stopped/started). new to this so go easy on me!
Here's some info that might be helpful. happy to provide more as needed...
As per some instruction # Passenger site i've created a symlink from /Library/WebServer/myapp/rails -> /Library/WebServer/rails/myapp/public
myhost:myapp joe$ passenger-config --root
/Library/Ruby/Gems/1.8/gems/passenger-2.2.14
myhost:myapp joe$ passenger-status
ERROR: Phusion Passenger doesn't seem to be running.
apollo:myapp joe$ cat /etc/httpd/httpd.conf
...
<removed for brevity>
...
# Copied From Passenger Installer
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.14/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.14
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
# End Passenger Installer
NameVirtualHost *
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /Library/WebServer/rails/myapp/public # <-- be sure to point to 'public'!
RackBaseURI /rails
<Directory /Library/WebServer/rails/myapp/public>
AllowOverride all # <-- relax Apache security settings
Options -MultiViews # <-- MultiViews must be turned off
order allow,deny
Allow from all
</Directory>
</VirtualHost>
This last bit from NameVirtualHost on is pieced together from a number of online material i've found...as i've been desperately trying to find something/anything that'll show Passenger at least has a pulse!?!
So, you've got
www.mydomain.com
www.mydomain.com/rails
These both point to different websites (lets call them main and rails), the code for each site might be saved on the file system like so:
/Library/WebServer/main/
/Library/WebServer/rails/
We create a symlink from your rails app's public folder to a folder called rails in your main app:
ln -s /Library/WebServer/rails/public /Library/WebServer/main/rails
Then we create a VirtualHost for the main site (not the rails one, and I'm assuming the main site is not rails) and add the rails app as a sub URI, like so:
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /Library/WebServer/main
<Directory /Library/WebServer/main>
Allow from all
</Directory>
RackBaseURI /rails
<Directory /Library/WebServer/main/rails>
Options -MultiViews
</Directory>
</VirtualHost>
(If you already have a VirtualHost set up for your main website, you can add the RackBaseURI and preceding Directory declaration to that instead).
Now restart apache and you should be able to go to:
www.mydomain.com/rails
and see the "Welcome to Rails" page, or:
www.mydomain.com/rails/controllername
Hope that helps.

Resources