Rails Production: Premature end of script headers - ruby-on-rails

I'm attempting to host my rails app on a vps. The issue that I'm running into is when I try to navigate to my rails app, I get the following error message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
When I check out the virtual server's error log it tells me the following:
Premature end of script headers:
And sometimes that's followed with a feed or a contact or a referer: myurl.com/ or nothing at all.
I've seen plenty of posts regarding this error messages elsewhere but none so far have resolved the matter. The general consensus seems to be that it likely has to do with the rails environment variable or file.
As this is my first attempt at putting a rails app on a production server, I figure this is plausible. Below is my environment.rb
cat config/environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
As for the server, I'm using Ubuntu 12.04 with Webmin/Virtualmin and apache2 with passenger. Ruby 2.1.5p273 was installed using RVM and all gems are up to date.
Any thoughts would be helpful!

Today I was confronted with exactly the same problem. In my case it was the line 'secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>' in config/secrets.yml (but the env variable was not defined on the server). Please, look in ยง3.3 of http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html.

Related

How to get useful errors to debug rails email on staging/production server?

I've been following the Ruby on Rails Book by Michael Hartl and am trying to setup Email in production as described here. The difference is that I'm using my own cPanel server instead of heroku with the sendgrid addon.
The problem is that every time I try to create a new user via the /signup form on the server I get the following unhelpful message:
We're sorry, but something went wrong.
I've tried to allow error reporting by:
adding
config.consider_all_requests_local = true
to my environments/staging.rb
and I've also set
config.log_level = :debug
which I think is the most verbose error level.
I've even tried changing- the staging server's environment to
RailsEnv development
in Apache's included config. But I still only get the "We're sorry, but something went wrong." message when trying to /signup a new user account.
Thanks in advance for any help.
You can use few gems to check error on server as,
Exception Notifier - this will send an email with full error trace
Rails Exception Handler - this allows us to store ruby/rails exception in database and also to customize error page
Forcing the environment setting with Apache's include config file to
RailsEnv staging
enabled helpful errors.

Rails production: Directory index forbidden by Options directive

I'm working on deploying my rails app using apache and passenger on a virtual server that I'm managing via Virtualmin. All of this is being hosted on an Ubuntu 12.04 VPS.
Anyway, I'm getting the following error.
Forbidden
You don't have permission to access / on this server.
At first, when this occurred, I was getting the error:
Premature end of script headers
in my virtual host error log and a key error in my apache error log. Both of these went away though once I updated my config/secrets.yml file. The 403 error, however has remained. Additionally, the virtual server error log had the error:
Directory index forbidden by Options directive
Additionally I've made sure that my public_html directory (and all of is subdirectories) is the right user for apache. I've checked the production error log, and apache error log and haven't seen anything come out when I load the page.
Any ideas as to what I should try?
Many thanks in advance

How can I debug my Rails application which encountered an internal server error?

I am using Rails 4.1 and Ruby 2.1.1 on Ubuntu.
My application is running just fine on the local development environment. When I moved everything to the production environment server, and tried the application URL, I got the following:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
The log file (production.log) has in it something about the migrations, but nothing else.
Where do I get started trying to figure out what this is about?
From original poster:
I followed the instructions and set up an environment variable for the secret_key. It turns out Rails 4.1 cannot read it and this seems to be a known issue. So, I had to put the key directly into secrets.yml and this solved the problem

No log messages in production.log

I wrote a demo HelloWorld Rails app and tested it with WEBrick (it doesn't even use a DB, it's just a controller which prints "hello world"). Then I tried to deploy it to a local Apache powered with Passenger. In fact this test is just to get Passenger working (it's my first deploy on Apache). Now I'm not even sure that Passenger works, but I don't get any error on the Apache side.
When I fire http://rails.test/ the browser shows the Rails 500 error page - so I assume that Passenger works. I want to investigate the logs, but it happens that production.log is empty! I don't think it's a permission problem, because if I delete the file, it is recreated when I reload the page. I tried to change the log level in conf/environments/production.rb, tried to manually write to log file with Rails console production and
Rails.logger.error('asdf')
it returns true but nothing gets written to production.log. The path (obtained per Rails.logger.inspect) is correct, and I remark that the file is recreated if I manually remove it. How can I know what's going on?
(I already checked the Apache logs, plus I set the highest debug level for Passenger but it seems a Rails problem, so is not logged by the server)
Assuming you're running Rails 3.2.1, this is a bug. It was patched in 3.2.2.
If you can't upgrade to 3.2.2 for any reason, this comment on GitHub has a workaround:
# config/initializers/patch_rails_production_logging.rb
Rails.logger.instance_variable_get(:#logger).instance_variable_get(:#log_dest).sync = true if Rails.logger
Setting this works on Rails 3.2.11:
Rails.logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log","production.log"))

Having problems deploying a Rails app to Fedora 8 w/Passenger

I'm using Capistrano and have everything configured. The weird issue I have is that before, I got a nice Passenger error saying what was wrong (I hadn't fully uploaded my vendor/rails directory). After I do that, however, I'm now getting the general Rails We're sorry, but something went wrong 500 error instead of the Passenger error page. My production log shows nothing (only that the log was created). Apache logs show nothing. I don't get why I'm no longer seeing the Passenger error that tells me exactly what is wrong; fixing the error Passenger was complaining about shouldn't prevent it from getting there, should it?
Can anyone help me?
FYI I'm running several PHP-based applications on the same server, with the rails app set as a subdomain (e.g. railsapp.mydomain.com). The full stack is:
Fedora Core 8
Apache 2.2.9
MySQL 5.0.45
Rails 2.3.4
Passenger 2.2.5
You have two issues at hand:
You're log file isn't writable by Passenger. Passengers runs as Apache. So make sure the webserver has the correct rights to write to the log/ directory.
You are probably missing a gem, database or configuration file. Can you start a console session?
./script/console production

Resources