I am using Ruby on Rails on a CentOS-server with apache 2.0. But somehow the root of the website does not load. It comes up as a download, with the right contents. But it needs to be server as html. Other links within the site are working fine (by adding a text/html type to the .htaccess). Also, when accessing the mongrel directly root does come up. Or when i put a index.html in the public folder of the rails app, it gets loaded as well.
My .htaccess:
DefaultType text/html # added for the other pages to get them working, like /products
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule .* "http://127.0.0.1:12001%{REQUEST_URI}" [P,QSA,L]
Rails version: 2.3.8
Mongrel version: 1.1.5
Apache version: 2.0.63
Due to a bug in mongrel_start, it wasn't working properly. This fixed the problem. Hope it can be a help for someone else in the future as well.
Related
Is it possible to just upload my RoR files to my server (eHost) and have my website up and running?
If not, what should I do in order to have it working on any Host with support for RoR? I know of heroku but it is quite expansive for me right now. eHost charges only $3.27 per month and they claim to have support for RoR. I even called Tech Support and asked them to update the vertion to 2.3.0(Ruby) and 4.2.4(Rails).
I am new on RoR and have no idea of how to host my application on the ordinary hosts out there. So any help will be very welcome.
I've not tried this, I only hope this gives you an idea,
They say they support Ruby and RoR, So taking a look https://support.ehost.com/articles/ruby-on-rails-and-gems they say it's on Apache CGI server.
So - this is my suggestion - you upload your project, and either you contact support or you might want to try the suggestion here:
http://blog.hulihanapplications.com/browse/view/52-how-to-install-a-ruby-on-rails-app-part-2 I'll quote the section (in case it ever becomes unavailable). It's under the section FastCGI/CGI:
Configure .htaccess
Apache usually looks in any web directory for an Override file(which lets you set your own Apache configuration settings for the directory) called .htaccess. For ruby on rails, we need a special .htaccess file that tells the server to set up the directory as a ruby on rails application. This file should be created in the public directory if it's not already there. Here's what the contents of the file should look like:
#AddHandler fastcgi-script .fcgi
#AddHandler fcgid-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteRule ^$ index.html [QSA]<br>RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
Linking to public
The public directory inside your rails application contains all your public resources(images, css, javascript, etc.), and well as the .htaccess file needed to run your application. Until now, your public directory hasn't been visible to the outside world. Now we'll link your application to a directory inside your web root.
For example, if I was planning on running my rails application in a subdirectory of my website called www.mywebsite.com/myrailsapp, you'll need to create a symbolic link(it's kind of like a shortcut) in your web root directory(remember, this is where your regular website stuff goes, usually named public_html or www). Let's also pretend that on the server, the path to your web root is /home/myaccount/public_html and the path to your rails application is /home/myaccount/myrailsapp. Therefore, the command to create a symbolic link will be:
ln -s /home/myaccount/myrailsapp/public /home/myaccount/public_html/myrailsapp
We have purchased Verisign SSL for a Domain for https://www.domainname.com ; the problem is that it does not work for https://domainname.com. I am using ssl_requirement Gem: https://github.com/rails/ssl_requirement
So I patched the Gem to also redirect non www ones to https://www.domainname.com and it worked well for the following scenarios:
http://www.domainname.com => https://www.domainname.com
http://domainname.com => https://www.domainname.com
But not for the scenario where someone types:
https://domainname.com
It seems that the server throws error before Rails takes control. Here are the details of the server:
OS: RHEL 5.5
Ruby: 1.9.2
Rails: 3.0.10 (on RVM)
Web Server: Apache with Passenger
Thanks for your help.
Here's the code I use to redirect from domainname.com to www.domainname.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname.com [nc]
RewriteRule (.*) http://www.domainname.com/$1 [R=301,nc]
This goes in the .htaccess file at the root level of the www directory.
Here's another writeup about SSL in Rails 3.1:
http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/
You will prob have to handle this at apache level using a .htaccess file in the public dir of your rails app.
for the www rewrite rule see this SO answer: use htaccess to add www with https support
Also if your going to ssl your whole app have a look at Rack::SSL middleware - it handles secure cookies and such. This post has a good write up on using it and also avoiding mixed content warnings.
http://collectiveidea.com/blog/archives/2010/11/29/ssl-with-rails/
Hope this helps.
NOTE: Just got to thinking, this may not work still, if it doesn't you may have to setup a specific VirtualHost to handle that scenario, hopefully not.
I've found the rack-rewrite gem to be particularly helpful here, particularly since Heroku doesn't use .htaccess. Gem: https://github.com/jtrupiano/rack-rewrite
Here's an example configuration in config/environments/production.rb
ExampleApp::Application.configure do
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
r301 /.*/, Proc.new {|path, rack_env| "http://www.#{rack_env['SERVER_NAME']}#{path}" }, :if => Proc.new {|rack_env| rack_env['SERVER_NAME'] !~ /www\./i}
end
#... the rest of production environment config.
end
Check it out as my gist at: https://gist.github.com/1843097
Edit:
Well maybe this can give a clue. When created a Rails app in cPanel on my web host, in order to access the app you need to create a rewrite rule. Which I did, but didn't know what it did. I tracked it down to it creating the following 2 files:
home/mydomain/public_html/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
and
home/mydomain/.cpanel/ruby-on-rails-rewrites.db:
appname: helloworld
domain: mydomain.com
port: 12030
rewritebasepath: /home/mydomain/public_html
url:
It seems that the root URL gets sent to Rails, but any other URL does not and I get an Apache 404 (not a Rails 404). Is there something wrong in the .htaccess file?
Is the rewrite condition only for the domain root? If it is, how can I make it for any URL ?
Original post:
I'm trying to deploy a rails website that works fine locally but not on the web server.
The rails app starts fine and I can access the home page. But any other link results in a 404.
My home page is set from within routes.rb like so:
map.root :controller => "home"
I am using RESTful routes and it works fine locally. In routes.rb all I have is a bunch of
map.resources :posts
map.resources :images
...
If I change the map.root to another controller (i.e map.root :controller => "posts", then that single page will display fine as well, and all other links will return 404s, including the one that previously worked when it was the one referenced in map.root.
This is my first rails deployment so it might be me doing something wrong. My web host tech support told me it's a coding issue and that they can't help me.
My website directory structure online is like so:
/home/mydomain/etc/rails_apps/mysitedir/ <- rails folders (app, config, db, ...)
/home/mydomain/public_html/ <- nothing here
Also, the files that are in my rails public folder, do they need to stay in that folder or should they be put in the public_html folder on the web? Because right now they're not found either. If I put them in the public_html folder though, they are found from the home page (javascript and css and images).
In my error log in cPanel, it shows errors like:
[Mon Oct 05 08:19:41 2009] [error] [client XX.XX.XX.XX]
File does not exist: /home/mydomain/public_html/market,
referer: http://www.mydomain.com/
Where market is one of the links I'm trying to access from my home page, for example, and it's one of my controllers.
In short, the only location I can access is the root.
What am I doing wrong that I am getting all these 404s?
I do not have shell access, all I have is cPanel. This is with Ruby 1.8.5 and Rails 2.3.4, the (shared) web server is Linux + Apache 2.2.11 (Unix).
You need to get your web root to point to /home/mydomain/etc/rails_apps/mysitedir/public/ Maybe this can be configured in cpanel?
If you can get access the shell you would do something like(syntax may vary slightly):
ln -s /home/mydomain/etc/rails_apps/mysitedir/public/ /home/mydomain/public_html
Note that you need to remove public_html first, you should verify that there are no negative consequences of this.
The problem is with my web host. Still hasn't been resolved by them.
I came across the exact same problem and found a fix. In the .htaccess file, remove that first '$' so you have:
RewriteRule ^/? "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
That first bit is a Regex, so the $ matches the end of the URL.
As a side-rant, this is the umpteenth problem I've had to solve today because cPanel sucks.
Our current Apache installations are running Apache 2.0. Now we'd like to add some Rails applications and plan to run them on Apache with Phusion Passenger. I've gotten conflicting reports about whether we need to upgrade Apache to 2.2 in order to use Passenger (a consultant I highly respect recommended that; someone from Phusion says 2.0 should be fine.
Anybody running Passenger with Apache 2.0 in production?
I was under the impression that the minimum version for Apache with Passenger was 2.2, but if you head over to their site and look in the Users Guide I'm sure it will say what you need.
i was choose this way. (optional)
im havent using Pasenger when production, i get simple deploy rails now. only create rails app # etc/rails_app/myapp/ and upload all app folder and public to myapp/app. then i just need to unchecklist # environment for production and configurated at database.yml
then i copied public # http/public_html folder
run mongrel -> rewrite 12007 to 80 -> restart mongrel
if u get problem, ur app only apper in index, and get error when link to another page.
only ask to admin host to configur .httaccess
for example like
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myapp.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.myapp.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12007%{REQUEST_URI}" [P,QSA,L]
or do like railsninja said :)
Since no one seems to have a definitive answer, I'm going to assume that the answer I was given by someone at Phusion is definitive. It's on Google Groups at http://groups.google.com/group/phusion-passenger/browse_thread/thread/789f4f6e8f1c542d.
He states that Apache 2.0 and up should be fine. (As it worked out, we were able to go with Apache 2.2 for this server, so the point was moot for us.)
You don't need 2.2. 2.0 works fine and if it doesn't it's considered a bug. That said 2.2 is probably better than 2.0 so regardless of the minimum supported version you should go for 2.2.
I'm trying to get Redmine (a Ruby on Rails app) working. It works fine when started with ruby script/server webrick -e production, however, I'm having trouble getting it working in Apache with Passenger.
Accessing http://example.com/redmine returns the Redmine home page, but clicking any link (or even adding a / to the URL) results in a 404. According to the Rails log, a RoutingError occurs. For example, when opening the projects page: ActionController::RoutingError (No route matches "/projects.html" with {:method=>:get})
The Redmine directory is /var/www/localhost/htapps/redmine. I followed the documentation at http://www.modrails.org/documentation/Users%20guide.html#_deploying_a_ruby_on_rails_application (section 3.2), so there's a symlink at /var/www/localhost/htdocs/redmine pointing to ../htapps/redmine/public, and the Apache configuration contains DocumentRoot /var/www/localhost/htdocs and RailsBaseURI /redmine.
What is causing it to raise these RoutingErrors?
It looks like this issue was actually caused by the default .htaccess included with Redmine.
Redmine's .htaccess rewrites every request to end with .html. Redmine's routes expect .html-less requests.
Setting RewriteEngine to Off solved the issue for me.
http://ptspts.blogspot.com/2009/05/how-to-fix-railsbaseuri-sub-uri-with.html
The manual workaround (according to what is suggested on the pages above) is adding the line below to config/environments/production.rb:
config.action_controller.relative_url_root = '/redmine'
If not deploying to a Sub-URI and deploying using passenger, adding the rule RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] to your public/.htaccess also solves the issue. As that rule is IfModule-ed out in the default .htaccess.
Another option is to delete .htaccess if you're not using it (As an example you may be using it for additional layer authentication with AuthType Digest etc). It is not required when deploying with passenger.
Even if you will manage to run Redmine in suburi, redmine still will have issues.
Some pages won't be parsed and displayed correctly, if displayed at all.
This issue is almost one year old and indicated for next minor release. Btw dozen minor releases came out, but it's not yet fixed. FCGI mode does not support sub-URI.