Ruby on rails & Passenger & paperclip | Image uploaded but 404 on passenger mod - ruby-on-rails

Everything works on the Ror's own server (Webrick), but when I tried out on Apache(+Passenger mod) I got always 404 (not found) error.
You can check this here: http://keidan.hopto.org/rails/phoenix/public/guild.
I think the main problem is that I can't access the app's public folder...
My vhost file:
ServerName keidan.hopto.org
ServerAlias keidan.hopto.org
DocumentRoot /var/www/
RackBaseURI /rails/phoenix/public
<Directory /var/www/rails/phoenix/public >
AllowOverride all
Options Indexes FollowSymLinks -MultiViews
Order allow,deny
Allow from all
</Directory>
...

Related

Trouble configuring a sub-uri with Apache 2, Rails 3.2, and Phusion Passenger

I need some help getting a Rails 3.2 app working in a sub-uri of a cPanel-configured Apache site. I've followed the steps from the Passenger docs and various blog posts. The root action renders fine, but every other request gives me a 404.
I think it is something in the Apache, not Rails, config, because it's not the Rails app's 404 page, and the 404s do not leave traces in the Rails log.
Here is the vhost section from httpd.conf, generated by cPanel:
<VirtualHost myip:443>
ServerName mysite.org
ServerAlias www.mysite.org
DocumentRoot /home/myuser/public_html
ServerAdmin webmaster#mysite.org
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /usr/local/apache/domlogs/mysite.org combined
CustomLog /usr/local/apache/domlogs/mysite.org-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myuser # Needed for CPanel::ApacheConf
UserDir disabled
UserDir enabled myuser
<IfModule mod_suphp.c>
suPHP_UserGroup myuser myuser
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup myuser myuser
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid myuser myuser
</IfModule>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mysite.org.crt
SSLCertificateKeyFile /etc/ssl/private/mysite.org.key
SSLCACertificateFile /etc/ssl/certs/mysite.org.cabundle
CustomLog /usr/local/apache/domlogs/mysite.org-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myuser/public_html/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
Include "/usr/local/apache/conf/userdata/ssl/2/myuser/mysite.org/*.conf"
</VirtualHost>
Here is the current version of the include file I put together for the sub-uri:
RewriteEngine On
RewriteOptions Inherit
RailsEnv production
<Directory /home/myuser/public_html>
Options Indexes FollowSymLinks -MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RackBaseURI /home/myrailsapp/current
<Directory /home/myuser/public_html/railsapp>
Options -MultiViews
</Directory>
/home/myuser/public_html/railsapp is a symlink to /home/myrailsapp/current/public
Here is /home/myrailsapp/current/public/.htaccess
RackBaseURI /railsapp
SetEnv GEM_HOME /usr/local/lib/ruby/gems
PassengerEnabled On
PassengerAppRoot /home/myrailsapp/current/
All files in /home/myrailsapp and /home/mysite are owned by myuser. (I'm not seeing any permissions errors.)
In my routes file:
resources :widgets
root :to => 'widgets#index'
When I navigate to https://mysite.org/railsapp it correctly displays the widgets index, including assets. When I go to https://mysite.org/railsapp/widgets or https://mysite.org/railsapp/widgets/index, I get the Apache 404, and no entry in the Rails log.
What am I missing?
It turns out .htaccess in /home/myuser/public_html was rewriting everything. Requests for /mysite/railsapp were exempted because it matched a directory name. I solved the problem by adding
RewriteEngine off
to /home/myrailsapp/current/public/.htaccess.
Adding RewriteEngine off to .htaccess does solve the problem.

Push redmine to the root of a subdomain

I just installed redmine and I would like to reach it from redmine.domain.com instead of domain.com/redmine.
I first tried to do this by myself with my few Apache knowledge but I got the following error:
So I looked for a support on the internet and found this page. I consequently adapted my Apache configuration file:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName redmine.mydomain.com
ServerAdmin admin#mydomain.com
DocumentRoot /var/www/redmine
<Directory /var/www/redmine>
Allow from all
Options -MultiViews
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/private/redmine.mydomain.com.crt
SSLCertificateKeyFile /etc/ssl/private/redmine.mydomain.com.key
</VirtualHost>
</IfModule>
And made some check ups, all seems good. However, when I go to my redmine.mydomain.com I see the hierarchy of /usr/share/redmine/public.
To cite from the page you linked to:
The virtual host’s document root must point to your Rack application’s public folder.
Thus, you have to configure Apache's DocumentRoot to point to /var/www/redmine/public.

Apache crashing when I add Far-Future Expires clause from Rails Guide

In an attempt to serve my precompiled assets with Apache, per this Rails Guide I try to change this:
<VirtualHost *:82>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/release_checklist/public"
<Directory "C:/RubyStack-3.2.5-0/projects/release_checklist/public">
Allow from all
Options -MultiViews
</Directory>
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPreserveHost On
</VirtualHost>
To this:
<VirtualHost *:82>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/release_checklist/public"
<Directory "C:/RubyStack-3.2.5-0/projects/release_checklist/public">
Allow from all
Options -MultiViews
</Directory>
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPreserveHost On
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
in my httpd.conf file. However, the Apache server won't start when the second option has been added. What am I doing wrong?
What error does it give you? Are you sure you have mod_expires compiled into apache and that the module is loaded?
Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration
Yeah, that's usually the error you get if you use a directive that's mapped to a module that isn't loaded (or just a mispelled directive, which appears the same to apache). You'll need to check httpd.conf and make sure the LoadModule expires_module modules/mod_expires.so line is not commented out, of if it's missing, to add it. Depending on your apache's version, the line can be slightly different.

Why does rails app show /public index listing instead of actual app?

How do you set up apache to show the rails app once it is on the server? My rails app works perfectly on the localhost, but when I go to the external site it gives me the index information
like this
Name Last modified Size Description
[TXT] 404.html 21-May-2012 21:38 728
[TXT] 422.html 21-May-2012 21:38 711
[TXT] 500.html 21-May-2012 21:38 643
[IMG] favicon.ico 21-May-2012 21:38 0
[TXT] robots.txt 21-May-2012 21:38 204
This is my virtual host information
<VirtualHost *:80>
ServerAdmin example#example.com
ServerName server.example.com
# ServerAlias
DocumentRoot /var/www/sample_app/current/public
ErrorLog /var/www/sample_app/error.log
RailsEnv production
<Directory "/var/www/sample_app/current/public">
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
OK that might not be it, but here's what Passenger's documentation recommends:
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
It's clearly stated that MultiViews is not compatible with Passenger.
So you could try:
Removing the Indexes option
Specifying -MultiViews instead of MultiViews
To be honest, I've tried adding Indexes to a production app of mine, as I thought that might just be this option that caused the problem, but it didn't change anything... so it's a bit of a "wild guess" that it might fix things on your side.
UPDATE
From another answer, what you could try is adding the PassengerResolveSymlinksInDocumentRoot option:
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
</Directory>
</VirtualHost>

I can't see the images of the web debug toolbar

I can't see the images of the web debug toolbar.
I'm getting this error for example:
GET
http://francesca.localhost/web/sf/sf_web_debug/images/close.png
404 (Not Found)
If I request http://francesca.localhost/sf/sf_web_debug/images/close.png it works ok (the image is showed).
This is my virtual host:
<VirtualHost 127.0.0.1:80>
ServerName francesca.localhost
ServerAlias francesca.com
DocumentRoot /home/me/programacion/francesca
<Directory /home/me/programacion/francesca/web>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch
Allow from All
</Directory>
Alias /sf /home/me/programacion/francesca/lib/vendor/symfony/data/web/sf
<Directory "/home/me/programacion/francesca/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
sf 1.4
Javi
You must have DocumentRoot /home/me/programacion/francesca/web

Resources