Source code served for Ruby files

34 views
Skip to first unread message

Michal Blazejczyk

unread,
Apr 19, 2013, 11:25:05 AM4/19/13
to phusion-...@googlegroups.com
Hi,

We have a legacy Rack app. We had to migrate the server (hardware trouble) and now we can't get it off the ground. No one of us is a Ruby developer but we have a good knowledge of Linux, Apache, PHP etc.

The app seems to be using the CGI handler. We are running on top of Apache using Passenger.  The server is CentOS release 6.3, Apache/2.2.15, Phusion Passenger version 3.0.19, ruby 1.8.7, `gem list --local` shows rack (1.4.1, 1.1.0).

The main page (config.ru - see below) displays fine, but all other files (from htdocs subdirectory) are served as source code or offered as a download.

The directory structure is very simple:

/var/www/domain
config.ru
htdocs
faq.rb
other.rb


Here is the content of faq.rb.  All of our rb files look similar.

#!/usr/bin/ruby

require 'rubygems'
require 'rack'

APP_ROOT = '/var/www/op.pharmacogenomics.ca/app'
TEMPLATE_ROOT = File.join(APP_ROOT, 'views')
require "#{APP_ROOT}/models/optimus"

class OPIndex
  def call(env)     
    @CONTENT = {}
    input = File.open(File.join(TEMPLATE_ROOT, 'optimus', 'faq.html.erb')).read
    @CONTENT['main'] = ERB.new(input, nil, '<>').result(binding)

    template = File.open(File.join(TEMPLATE_ROOT, 'layouts', 'application.html.erb')).read
    html = ERB.new(template, nil, '<>').result(binding)

    [ 
      200, 
      { "Content-Type" => "text/html" }, 
      html
    ]
  end
end

app = Rack::Builder.new do 
  use Rack::ShowExceptions
  run OPIndex.new
end

Rack::Handler::CGI.run(app)

Apache configuration:

LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.19
PassengerRuby /usr/bin/ruby


And in vhosts.d:

<VirtualHost *:80>
    ServerName op.pharmacogenomics.ca
    ServerAlias pharmacogenomics.ca
    DocumentRoot /var/www/op.pharmacogenomics.ca/htdocs

    RackBaseURI /
    CustomLog /var/www/op.pharmacogenomics.ca/logs/access_log combined
    ErrorLog /var/www/op.pharmacogenomics.ca/logs/error_log
    LogLevel warn
    <IfModule peruser.c>
        ServerEnvironment apache apache
        MinSpareProcessors 4
        MaxProcessors 20
    </IfModule>

    <Directory /var/www/op.pharmacogenomics.ca/htdocs>
         AllowOverride all
         Options -MultiViews
    </Directory>
</VirtualHost>

I tried naming the folder public instead of htdocs.  I tried removing the IfModule directive.  I added AddType application/x-httpd-ruby *.rb to .htaccess and to httpd.conf.  Nothing.

What are we doing wrong???

Best,
Michal
 

Tinco Andringa

unread,
Apr 23, 2013, 6:59:03 AM4/23/13
to phusion-...@googlegroups.com
Hi Michal,

From the looks of it your configuration is correct. I think you should be able to drop the RackBaseURI directive as Passenger would detect that automatically. Could you try setting the passenger log level to 3, it should give some more information then, is there anything interesting to see there when you try a request? Is there nothing in your .htaccess file? No fancy other modules?

Kind regards,
Tinco


--
You received this message because you are subscribed to the Google Groups "Phusion Passenger Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phusion-passen...@googlegroups.com.
To post to this group, send email to phusion-...@googlegroups.com.
Visit this group at http://groups.google.com/group/phusion-passenger?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Phusion | Ruby & Rails deployment, scaling and tuning solutions

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Michal Blazejczyk

unread,
Apr 26, 2013, 2:18:06 PM4/26/13
to phusion-...@googlegroups.com, ti...@phusion.nl
Hi Tinco,

Thank you for you answer.  It was very useful, actually.

I ended up fixing my web app by using the map() function - this way, config.ru responds to all relevant URLs.

Best,
Michal
Reply all
Reply to author
Forward
0 new messages