Using Mac OS X Yosemite (10.10.2) with Ruby 2.1.5 and Nginx 1.6.2 and Passenger 5.0.5 installed via Homebrew.
You are developing an app / website and have done most of the development using thin / webbrick etc without any problems, and now when you try to view your website / app in Nginx / Passenger you encounter this problem:
App 16220 stderr: [ 2015-04-07 08:05:46.0788 16486/0x007fc56c07b640(Worker 1) utils.rb:85 ]: \
*** Exception Encoding::InvalidByteSequenceError in Rack application object \
(/path/2/app.dev/current/apps/main/views/layout.erb is not valid US-ASCII) \
(process 16486, thread 0x007fc56c07b640(Worker 1)):
The key part there being:
Exception Encoding::InvalidByteSequenceError in Rack application object \
(/path/2/app.dev/current/apps/main/views/layout.erb is not valid US-ASCII)
or (the full stack trace)
App 16220 stderr: [ 2015-04-07 08:05:46.0788 16486/0x007fc56c07b640(Worker 1) utils.rb:85 ]: *** Exception Encoding::InvalidByteSequenceError in Rack application object (/Users/kematzy/Sites/testapp.dev/current/apps/main/views/home.erb is not valid US-ASCII) (process 16486, thread 0x007fc56c07b640(Worker 1)):
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/tilt-2.0.1/lib/tilt/template.rb:83:in `initialize'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/tilt-2.0.1/lib/tilt/mapping.rb:136:in `new'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/tilt-2.0.1/lib/tilt/mapping.rb:136:in `new'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/tilt-2.0.1/lib/tilt.rb:43:in `new'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda/plugins/render.rb:154:in `block in render'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda/plugins/render.rb:195:in `cached_template'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda/plugins/render.rb:150:in `render'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda/plugins/render.rb:170:in `view'
App 16220 stderr: from /Users/kematzy/Sites/testapp.dev/current/apps/main/app.main.rb:33:in `block (2 levels) in <class:MainApp>'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:712:in `always'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:616:in `root'
App 16220 stderr: from /Users/kematzy/Sites/testapp.dev/current/apps/main/app.main.rb:31:in `block in <class:MainApp>'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:249:in `instance_exec'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:249:in `block in call'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:247:in `catch'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:247:in `call'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda/plugins/error_handler.rb:52:in `call'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/roda-2.1.0/lib/roda.rb:221:in `block in build_rack_app'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/static.rb:124:in `call'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/static.rb:124:in `call'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/session/abstract/id.rb:225:in `context'
App 16220 stderr: from /Users/kematzy/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/session/abstract/id.rb:220:in `call'
App 16220 stderr: from /usr/local/Cellar/passenger/5.0.5/libexec/lib/phusion_passenger/rack/thread_handler_extension.rb:85:in `process_request'
App 16220 stderr: from /usr/local/Cellar/passenger/5.0.5/libexec/lib/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
App 16220 stderr: from /usr/local/Cellar/passenger/5.0.5/libexec/lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
App 16220 stderr: from /usr/local/Cellar/passenger/5.0.5/libexec/lib/phusion_passenger/request_handler.rb:414:in `block (3 levels) in start_threads'
App 16220 stderr: from /usr/local/Cellar/passenger/5.0.5/libexec/lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'
[ 2015-04-07 08:05:46.0801 59453/0x10a48c000 age/Hel/Req/Utils.cpp:89 ]: [Client 1-34] Sending 502 response: application did not send a complete response
The solution to this problem is very simple, but hard to spot.
Inside your HTML you may have a mark like '©' or even a plain '–' or '—' (or similar characters).
Just remove those (most likely pasted) characters and type them again and the problem is solved.
This worked perfectly on my system, but your may be different.