70

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?

juicy
  • 865
  • 2
  • 8
  • 7
  • Have you tried setting `passenger_buffer_response off;`? http://stackoverflow.com/q/11738924/1454117 –  Mar 24 '15 at 19:23
  • 8
    @Avilyn Passenger author here. `passenger_buffer_response_off` is unrelated to his problem and won't help. A long time ago there was a bug in the response buffering code, but that bug has long been fixed, so the solution in the StackOverflow post you posted no longer applies. – Hongli Mar 31 '15 at 11:37
  • 3
    hello, i fixed it. it's because in the tutorial they missed to have an enviroment variable for "<%= ENV["SECRET_KEY_BASE"] %>" in the secrets.yml! – juicy Apr 01 '15 at 12:04

9 Answers9

130

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:

  1. Enter your app root
  2. run: rake secret
  3. copy the output
  4. go to /yourapp/config/secrets.yml
  5. set the production secret_key_base

Restart the passenger app :

touch /yourapp/tmp/restart.txt
Ajay Barot
  • 1,681
  • 1
  • 21
  • 37
Yaniv Vova Alterman
  • 1,660
  • 1
  • 13
  • 11
  • 4
    hello, i setup the <%= ENV["SECRET_KEY_BASE"] %> in my vserver ~/.bashrc: `export SECRET_KEY_BASE=12345678910111212andmore` – juicy Apr 01 '15 at 12:05
  • 7
    tempted to downvote... config/secrets.yml says `do not keep production secrets in the repository, instead read values from the environment` – Matthew Turner Apr 10 '15 at 00:24
  • 3
    It's really depends how smart you are :) – Yaniv Vova Alterman Apr 11 '15 at 17:01
  • 9
    You can work with secrets.yml and add it to .gitignore file so it will never been populated to you git provider, or you can work with ENV variables, i am working with both techniques and everything just fine. If your server will be hacked and the hacker will get access to your system it's really don't matter where you store your keys :) – Yaniv Vova Alterman Apr 11 '15 at 17:07
  • I've done this and I still can't get past the error, I'm also following the linked tutorial. I even verified that it loaded okay as development – Joe Sak May 14 '15 at 22:53
  • Can you send me your configuration files ? I strongly recommend to drop the passenger and move to Nginx + Puma it's much better set up :) – Yaniv Vova Alterman Jun 08 '15 at 07:33
25

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
Hoa Hoang
  • 1,212
  • 14
  • 20
6

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!

user208769
  • 2,216
  • 1
  • 18
  • 27
5

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

Ctpelnar1988
  • 1,235
  • 3
  • 15
  • 38
4

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.

mridula
  • 3,203
  • 3
  • 32
  • 55
1

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.

William Hu
  • 15,423
  • 11
  • 100
  • 121
1

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.

jeremywoertink
  • 2,281
  • 1
  • 23
  • 29
0

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~

fanjieqi
  • 472
  • 4
  • 11
0

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.

Andrew Koster
  • 1,550
  • 1
  • 21
  • 31