Topic: Apache config for Rails

I had to set up Apache/Mongrel on a windows box.

I've got it working to a point,  but can't figure this this out.

My rails app has one action that results in a send_data

      send_data(Rails.root.to_s + "/public/#{params[:app]}_#{rands}.pdf", 
        :type=>"application/pdf", :disposition=>'inline')

When I hit Apache with the appropriate route,  my action in rails is fired,  and I assemble a pdf (that takes about 1 second), and send it back.

I call the Rails app from another Rails app like so:

require 'open-uri'

open("http://pdftk.neeis.com/blah/deblah/deblah") {|f| f.read }

Apache always sends back 404, returning immediately, even though the Rails action is called, and moments later Rails happily send's the data requested, (to where I don't know,  because the call to open has already returned 404???)

I'm pretty sure this is a simple Apache configuration thing,  but I'm too new with it to understand.

ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.2"
Listen 172.28.1.10:80

LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule xsendfile_module modules/mod_xsendfile.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>
</IfModule>

ServerAdmin brad@tvdco.com
ServerName neeis.com:80
DocumentRoot E:/DEV/pdftk/public/

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>
ErrorLog "logs/error.log"
LogLevel debug
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access.log" common
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>


<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Redirect 404 /favicon.ico
<Location /favicon.ico>
  ErrorDocument 404 "No Favicon"
</Location>
RewriteEngine On
EnableSendfile On
EnableMMAP Off
ProxyRequests Off
ProxyVia On
XSendFile On
#XSendFileAllowAbove On 
Redirect 404 /favicon.ico
<Location /favicon.ico>
  ErrorDocument 404 "No Favicon"
</Location>
ProxyRequests Off
Include conf/extra/httpd-vhosts.conf

conf/extra/httpd-vhosts.conf

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<Proxy balancer://pdftk_cluster>
  BalancerMember http://pdftk:3005
  BalancerMember http://pdftk:3006
</Proxy>
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
  ServerName neeis.com
  DocumentRoot E:/DEV/pdftk/public/
  <Directory E:/DEV/pdftk/public/ >
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from any
  </Directory>
  RewriteEngine On
  RewriteRule ^/$ /index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{DOCUMENT_ROOT)/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://pdftk_cluster%{REQUEST_URI} [P,QSA,L]
</VirtualHost>  
<VirtualHost *:80>
    ServerName pdftk
    DocumentRoot E:/DEV/pdftk/public/
    XSendFilePath E:/DEV/pdftk/public
    <Directory E:/DEV/pdftk/public/ >
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from any
    </Directory>
    <Directory E:/DEV/pdftk/private/ >
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from neeis.com 98.189.35.146
    </Directory>
    RewriteEngine On
    RewriteRule ^/$ /index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{DOCUMENT_ROOT)/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://pdftk_cluster%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

Last edited by BradHodges (2010-11-12 12:29:23)

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Apache config for Rails

Figured this out,  there is a bug in mongrel when used with rails 2.3.8

https://rails.lighthouseapp.com/project … -rails-238

The workaround that worked for me is here:

http://gist.github.com/471663

BUT, this also had to be done (copied from the comments):

It fails with RubyGems 1.3.5, unless I make the following addition patch to his mongrel.rb:

$ diff mongrel.rb.orig mongrel.rb
2c2
< if Rails.version == '2.3.8' && Gem.available?('mongrel', Gem::Requirement.new('~>1.1.5')) && self.class.const_defined?(:Mongrel)
---
> if Rails.version == '2.3.8' && Gem.available?('mongrel', '~>1.1.5') && self.class.const_defined?(:Mongrel)

These fixes solved my problem.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.