"Incomplete response received from application" from nginx / passenger - ruby-on-rails

I tried to deploy my rails app on nginx and ubuntu via capistrano like the tutorial on the page https://gorails.com/deploy/ubuntu/14.04.
but at the end i get an error message:
Incomplete response received from application
in my browser.
this is probably an error from passenger, but how can i figure out what to do?

Your rails_env production don't have required set up,probably missing secret_key_base.
Open /etc/nginx/sites-available/default and change the rails_env to development:
rails_env production;
to
rails_env development;
If the app is loading it's not a passenger issue.
Production Solution:
Enter your app root
run: rake secret
copy the output
go to /yourapp/config/secrets.yml
set the production secret_key_base
Restart the passenger app :
touch /yourapp/tmp/restart.txt

This error occurs because you didn't set the secret_key_base. Follow these steps to fix it:
Go to your rails app directory
cd /path/rails-app
Generate secret key base
rake secret RAILS_ENV=production
Set environment variable
SECRET_KEY_BASE=<the-secret-key-base>
Restart the Rails app
touch /path/rails-app/tmp/restart.txt

I had this problem over the weekend (it turned out there was an incompatibility between my versions of passenger and ruby).
However, nobody seems to be mentioning: the actual error might appear in /var/log/apache2/errors.log, not in any custom log.
Once you know that, hopefully your search will be easier!
Update, since I needed to refer back to this again - this hold true for nginx too - /var/log/nginx/error.log is your friend in that case!

For those using Passenger:
• Navigate to root of your project.
• run bundle exec rake secret RAILS_ENV=production
• Copy the output and then run sudo nano config/secrets.yml
• Under production, replace the value of the secret_key_base with the recently copied rake secret.
• press CNTRL+X, then press y, then hit enter.
• run passenger-config restart-app and select the app you wish to restart.
https://www.phusionpassenger.com/library/admin/apache/restart_app.html

In my case, it was because my server was running out of RAM intermittently (during PDF generation). Once the PDF was generated, some RAM was restored and the error would disappear.
I had an ubuntu server with 500M of RAM.
I added some swap space and this error disappeared.

Might be my answer is off topic, but when my database mysql server isn't running, i got this error too. Just in case someone has the same error.
so start/restart your database might be another answer.

This means that your rails app tanked before actually getting to rails itself. This could be an exception in middleware, missing ENV key, something at the OS level.
Try booting the app locally first and doing what you did to get the error in production. If everything is fine, check all of your logs. Check nginx logs, your passenger logs, and finally any other OS specific logs pertaining to booting and running your app.

Is there anybody like me who got this error after uploading a file?
My solution is check the name of the file which may has some special characters like `[(~.
Just remove it then upload the file again.
Good luck~

I got this, only on my test server and not in production, because I was requesting a URL that didn't exist, and I guess in the test environment, Rails throws an error instead of returning a 404 response.

Related

Rails 5 Debug in Production Mode

I am trying to find a way to check logs or debug in production I am using passenger and apache and ubuntu as server. Every time I create any scaffold and upload it to server I get error :
I have used
bundle exec rake assets:precompile RAILS_ENV=production
But getting no success but when I am running application using :
rails s -e production
I can access my controllers and views over port 3000. What is wrong with this why assets:precompile is not working properly I am adding JS files manually not using coffee script. And my javascripts files are not complied.
My question is how can I set anything in production to see a debug like in development mode like this:
Can I do this in production I am using rails 5
The production error you have shown above was a 404 error. it means that the route doesn't exist or there are no controllers methods for that route or is a model not found error.
As for adding debuggers in production, can you do it?
Yes you can.
But should you do it?
NO, because it is a BAD practice. If you wish to view and debug errors in production, check your logs for the stacktrace and work with it from there. As long as it is a rails error, it will be in log/production.log.

check 500 internal server error in production mode in rails 3.2

I have my app in production mode in my linode account and I get in one page a 500 internal server error the message:
We're sorry, but something went wrong.
However in my development environment works fine this page.
How can I debug this error?
How can I see the error origin in my production mode?
I want that rails show errors in production mode.
How can I do it?
Thank you!
If you have access to ssh, log in to your server via ssh and go to your rails log directory, which is inside your rails directory.
Once you are there run the command tail production.log . If this doesn't give you enough information you can also do a tail -n100 production.log (gives you last hundred lines of the production log).
If you have deployed via heroku, then you can access the logs by running heroku logs in your local console. (more information here https://devcenter.heroku.com/articles/logging)
I also find it helpful to use the exception_notification gem https://github.com/rails/exception_notification when running in production, as it emails you a stacktrace when an error occurs. Plenty of others also use Hoptoad (http://hoptoadapp.com/) or Exceptional (http://www.exceptional.io/) however i prefer the simple exception_notification gem.
Also, in some rare occasions when i can't trace the error as a final measure i sometimes open up port 3000 temporarily on the remote server firewall and cd to the rails project and run rails server production with the log level set to debug in config/environments/production.rb so i can see the error in the console, and then close off the port when i have finished.
Hope that helps.
tail -n100 production.log
will only show the last 100 lines of the log file. Just in case you want to see the log running in real time.
use this
tail -1000f log/production.log

Capistrano Rails app SQLite3 Cannot open Database

I've managed to get a Rails app deployed with Capistrano to a server running NGinx & Passenger. On deploy I was getting the "We're sorry, something went wrong" message & was rather confused as the production log was blank. I then switched the rails_env to development in my NGinx Conf & now I'm getting:
SQLite3::CantOpenException
unable to open database file
Rails.root: /www/testcap/releases/20120407015032
I logged into the server, into the current folder within testcap (which I believe symlinks to the latest release) and ran rake db:create, however the db files exist. Having looked within the app's db folder I see both development.db & test.db.
If I run rails s -e production and then head to myurl.com:3000 the app works completely fine, which is weird, and it also works fine when I run rails s -e development too.
I'm at a complete loss as to what the issue might be here. I'm sure it must be a relatively obvious issue, potentially with capistrano? I'm still new to it so I could well have missed anything but googling so far has been fruitless.
The only thing I can think of is that I've nothing explicitly relating to databases in my config/deploy.rb ? However I've not been able to find any guides on the net to help out thus far.
Thanks in advance for your help :)
Jack.
Thanks to the comments from Adam P & Ben L above, I managed to make some head way on this. This Guide also solved my issue.
I followed the steps in that guide above and in my database.yml file I changed the path to the production db from:
`db/production.sqlite3`
To
`/www/testcap/shared/db/production.sqlite3`
(eg the absolute path)
I then added this to my config/deploy.rb:
role :db, "{my vps IP}", :primary => true
On my VPS I went into the nginx conf & removed the line rails_env development (Passenger then sets it to production by default).
And then ran cap deploy followed by cap deploy:migrate, which worked, and I get the app displayed when I visit the URL.
I hope this might help someone out in the future stuck on the same issue :)
Jack.

How to properly diagnose a 500 error (Rails, Passenger, Nginx, Postgres)

I'm having a real tough time diagnosing a 500 error from my application running in production. I've had it working before, but after re-deploying via Capastrano I am unable to get it going.
Here are the facts:
The server is setup with nginx + passenger, and I'm using
PostgreSQL.
Static assets are working properly, as in I'm able to access them just fine in a browser.
I can access the rails console via RAILS_ENV=production bundle exec rails console and perform Active Record actions (like
retrieving data from the db).
Within console, I can run app.get("/"), which returns a 500 error as well (after first showing the query that was run to load
the model).
The production.log file is never written to. I've set permissions 777 on it just for the hell of it. I've also set the log level to
:debug with nothing to show for it.
The nginx log (which passenger also uses) shows no indication of errors, it just notifies about cache misses.
Because nothing of use is being logged, I have no idea what to do here. I've tried setting full permission on the entire app directory with no help. Restarted the server multiple times, nothing. The database is there and rails can clearly communicate with it. I'm not sure what I did to get it to run the first time around. I just don't know why rails isn't outputting anything to the log.
Okay, I figured this out. The app ran fine in development mode, so I knew something production-specific was screwing it up. I went into config/environments/production.rb and changes these settings:
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false # changed from true
config.action_controller.perform_caching = true # changed from false
And then after restarting passenger, rails showed me the error w/ stacktrace. Turns out I was forgetting to precompile the asset pipeline!
Things to check
1) Are you sure you are running in production environment?
Check to see if any entries are in the development.log file
2) Set up your app to email you when a 500 error occurs with a full stack trace. I use the Exception Notifier gem but there are plenty of other solutions for this.
3) When checking your app in the console are you sure you are starting the console in production mode? It is possible that the app is not starting up at all and you just forgot to set the production param thereby thinking that the app runs fine when it doesn't.
4) Are you getting an nginx 500 error or the Rails 500 error? If nginx then it is likely that your app is not starting at all and highly unlikely that you will get any rails error in your log file. The assets are static files and navigating to them proves nothing other than that they exist.
5) Are you sure you are checking the right folder on the server? Sounds really stupid but capistrano could be deploying the app to a folder that is different to the folder that nginx is looking for for your app so double check both the folder capistrano is deploying to and the folder that nginx is looking for are the same.
Just a suggestion, I would use puma rather than passenger. It's awesome with nginx.
My problem is passenger's log file (error.log) has nothing. Then it's a rotation log issue. Run
passenger-config reopen-logs
solved my problem. More.
Have you tried running in development mode to see if the error reports itself?

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