Configuring Ruby On Rails App in a subdirectory under Apache - ruby-on-rails

I've got apache2.2 on windows. I'm trying to serve both subversion (/svn) and redmine (/redmine). I have svn running fine with this config:
<Location /svn>
DAV svn
SVNParentPath C:/svn_repository
...
</Location>
This is working great--my svn users can hit http://mybox/svn just fine.
Now I want to add another directory for a rails app (RedMine):
I followed the advice in this question to setup a mongrel server and have apache proxy clients through to it. It works fine if I make it the root--but I'm having trouble making it in a subdirectory:
<Location /redmine>
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
Any suggestions?

Here's what I had to change:
I removed the trailing slash:
<Location /redmine>
ProxyPass http://localhost:3000
ProxyPassReverse http://localhost:3000/
</Location>
And in my rails app:
# added to end of file C:\redmine\config\environment.rb
ActionController::AbstractRequest.relative_url_root = "/redmine"
Now it's working!
I wasn't completely happy with this approach--I ran into some redirect issues. This is another attempt which seems to be working well so far.
Fast CGI and Fast CGI without VirtualHosts
Tuning Fast CGI
This second approach seems better.
UPDATE:
As noted in the comments, for more recent apps running on Rails 2.3.2+, use this instead:
config.action_controller.relative_url_root = '/redmine'
I put it in the new additional_environment.rb file.

In case you still wish to use Mongrel + Apache using a reverse proxy here is how I solved the same issue on our system (Win2k3, Apache 2.2, trunk of Redmine). The secret is to install your mongrel service using --prefix /redmine which tells it to serve it from http://localhost:port/redmine
In Apache httpd.conf (or suitable include file):
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<IfModule mod_proxy.c>
ProxyRequests Off
#No need to forward on static content - let apache do it faster
ProxyPass /redmine/images !
ProxyPass /redmine/stylesheets !
ProxyPass /redmine/javascript !
# Remove the following entry on public sites as this is insecure
ProxyPass /redmine/plugin_assets !
ProxyPass /redmine/help !
ProxyPass /redmine http://localhost:4000/redmine
ProxyPassReverse /redmine http://localhost:4000/redmine
ProxyPreserveHost On
#continue with other static files that should be served by apache
Alias /redmine/images C:/Repositories/redmine/public/images/
Alias /redmine/stylesheets C:/Repositories/redmine/public/stylesheets/
Alias /redmine/javascript C:/Repositories/redmine/public/javascript/
# Remove the following on public sites as this is insecure
Alias /redmine/plugin_assets C:/Repositories/redmine/public/plugin_assets/
Alias /redmine/help C:/Repositories/redmine/public/help/
</IfModule>
# Make sure apache can see public and all subfolders - not suitable for public sites
<Directory "C:/Repositories/redmine/public/">
Allow from all
Order allow,deny
</Directory>
Mongrel is installed as such:
mongrel_rails service::install --prefix /redmine -N redmine_prod -p 4000 -e production -c C:\Repositories\redmine
Hope that helps someone. Initially, I tried setting up Apache + fastcgi etc but I lost more precious hair - it's not Windows friendly.
P.s. I found this PDF a very useful referene: http://www.napcsweb.com/howto/rails/deployment/RailsWithApacheAndMongrel.pdf
/Damien

Passenger (http://modrails.com) is a better alternative to fastcgi because it's very easy to configure I would recommend using this for hosting your rails apps using a similar configuration to what you have now

I agree with Radar. Passenger is really easy to set up, lets Rails apps share memory, removes the burden of managing a cluster of mongrels and requires virtually no configuration. All you need are a special 'config.ru' file with a RackUp config and a DocumentRoot pointing to RAILS_ROOT/public set in Apache.

Related

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.

Rails, Apache, Thin on Windows. Better configuration for httpd.conf

I'm using this configuration with the lines in this good answer (Rails Deployment Environment on Windows):
<VirtualHost *:82>
# Your server's web or IP address goes here.
# You can leave at localhost if deploying to
# company intranet or some such thing.
ServerName localhost
# Customize the next two lines with your app's public directory
DocumentRoot "C:/RubyStack-3.2.5-0/projects/app_name/public"
<Directory "C:/RubyStack-3.2.5-0/projects/app_name/public">
Allow from all
Options -MultiViews
</Directory>
RewriteEngine On
# Redirect all non-static requests to Rails server,
# but serve static assets via Apache
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://app_balancers%{REQUEST_URI} [P,QSA,L]
# Serves dynamic rails assets from multiple servers
# to improve performance. A Rails server such as
# thin or WEBrick must be running on at least one of
# these ports in order for Apache to serve your site
<Proxy balancer://app_balancers>
BalancerMember http://localhost:3001/
BalancerMember http://localhost:3002/
</Proxy>
# Support for far-futures expires header
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
But browsing, I found other articles and other questions of other people who have configured Apache httpd in a different way, by adding or subtracting configuration lines.
Like here: http://www.varyonic.com/2011/06/using-apache-with-mongrel-or-thin-and-rails-3/#.VK5OhyuG9G6
What is it?:
ProxyPreserveHost On
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
Now, of course, I'm here to ask you: what is best for Rails 4 on Windows 8.1 / Windows 10?
The server Thin is the best for Windows 8.1/10? Mongrel? Other?
Alternatives to Apache for stability and speed?
The operating system is Windows and I can not change it.

How to use geminabox with Apache web server

I want to use geminabox with Apache web server. I have searched a lot on web but could not find any concrete information. Can some one please let me know how to do this ? Will appreciate detailed suggestions.
An easy way to use Geminabox with Apache is to configure a HTTP Reverse Proxy.
For this configuration, you just need two files:
1) The config.ru just like the example in the README.md file in the geminabox repository:
require "rubygems"
require "geminabox"
Geminabox.data = "include here the data path"
run Geminabox::Server
To run the server use rackup command. This will start the server in the 9292 port. If you want to change the port number use rackup -p XXXX.
2) In the Apache side, make sure that you have the mod_proxy and the mod_proxy_http installed. If yes, just include the following lines into your Apache config file:
ProxyRequests Off
ProxyPass / http://localhost:9292/
ProxyPassReverse / http://localhost:9292/
Restart the Apache and it is done!
geminabox is a ruby application, and just like all ruby applications, Apache does not support them out of the box.
With that said, a simple Google of how to use ruby applications with Apache lead me to this, which lead me to this. I have no experience with this tool. However, it is suggested by the rails team, so it has to have some merit.
I did work with Apache VirtualHost.
In folder /etc/httpd/conf.d/ create a file gems.conf, so add it to the file:
<VirtualHost *:80>
ServerName gems.mydomain
ServerAlias gems.local
DocumentRoot /var/railsapps/gems/public
</VirtualHost>
Where /var/railsapps/gems is the folder that have the config.ru.
The domain gems.mydomain must be in your DNS or /etc/hosts

Rails not rendering assets over SSL (404 Not Found error)

I am kind of new to Rails and am struggling with an issue that is preventing my assets to be found if I try to access my test app using an SSL connection.
As an example of what I am referring to, if you try to access
http://domain.com/testapp the default rails page loads fine and I have no issues at all.
You can also access a page I created using this route
http://domain.com/testapp/static_pages/home
However the same address, if accessed via HTTPS is returning 404 errors for all of my assets. I am also unable to access any routes (they all return 404).
https://domain.com/testapp
https://domain.com/testapp/static_pages/home
I am currently using an Apache server with Passenger installed, and here is what my virtual host configuration looks like:
<Directory /var/www/testapp/public>
PassengerEnabled on
PassengerAppRoot /var/www/testapp
RailsBaseURI /testapp
</Directory>
Any ideas of why this might be happening?
Thanks,
Rog
Thanks all, I finally figured out what was going on so in the interest of others having the same issue, the virtual host configuration was only being applied to the default port (80) so I had to specify port 443 as well.
<VirtualHost *:80 *:443>
<Directory /var/www/testapp/public>
PassengerEnabled on
PassengerAppRoot /var/www/testapp
RailsBaseURI /testapp
</Directory>
</VirtualHost>
For people using Media Temple's DV server, this configurations has to be specified in two separate files (make sure you remove the VirtualHost tags).
vhost.conf
vhost_ssl.conf
And don't forget to restart apache.
/usr/sbin/apachectl -K graceful

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