How to use deactivate Webrick's SSL - ruby-on-rails

Last week I tried to debug with SSL activated in webbrick, but I forget how to restore the settings to default(without SSL). Every time I visit a controller, now it shows:
SSL connection error
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
And below is the log from the console, can anyone help?
[2011-05-10 07:28:43] INFO WEBrick 1.3.1
[2011-05-10 07:28:43] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0]
[2011-05-10 07:28:43] INFO WEBrick::HTTPServer#start: pid=62854 port=3000
[2011-05-10 07:28:58] ERROR bad Request-Line `UQM?x?ʾ???????c??B?????n???BU???*???98?5EDf32?A/??'.

I just ran into this same exact problem today. I added config.force_ssl = true to the application.rb file and got the above error. When I removed the line, the error still persisted.
I fixed it by clearing my browser cookies (Chrome in this case) and it works again. It seems the authentication information is saved in the cookie and something i that keeps reverting our requests to HTTPS but does not authenticate correctly so you get that error. Clearing the cookie solves that issue.

I had a similar issue but wasn't able to fix it by clearing cookies on Chrome (nor any other fixes like rake tmp:clear), and ended up switching to using thin with SSL enabled as suggested in this post:
https://stackoverflow.com/a/11614213
Added this to my Gemfile:
group :development do
gem "thin"
end
Then bundle and thin start --ssl.

I had to use rake tmp:sessions:clear (not just rake:tmp:clear) as well as clearing cookies in the browser to fix this issue.

Open Chrome Developer Tools, click and hold "page reload" button, you will see some options,pick "Empty Cache and Hard Reload". Did the trick for me.

Similarly I recieved the same error after adding config.force_ssl = true in my config/locales/application.rb file
To remedy an SSL error, simply edit Rails.application.config.session_store :cookie_store, key: '_app_sessions' in config/initializers/session_store.rb
Changing the '_app_sessions' name to anything else will allow you to start your rails server without ssl and without error

Related

"Can't verify CSRF token authenticity" after new build on Heroku (Rails)

Just after a new deploy all POST request started throwing error 422 and "Can't verify CSRF token authenticity."
I rolled back to previous deploy and worked. I suspected an error on the code base (all thou nothing looked strange). So reverted to the exact same code as the build that worked. Push again but didn't help.
Have tried:
Build exact same code as the las deploy that worked.
Different browsers, incognito modes, errase cookies
Change SECRET_KEY_BASE
Restart server
Any advise apreciated.
Using rails 5.0.7.2
It was Rails5 + Heroku + CloudFlare as explained here:
http://til.obiefernandez.com/posts/875a2a69af-cloudflare-flexible-ssl-mode-breaks-rails-5-csrf
"The solution is simple. Make sure you have working SSL and HTTPS on Heroku (or wherever you're serving your Rails application.) Turn Cloudflare SSL to Full mode. Problem solved."

"Incomplete response received from application" from nginx / passenger

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.

SSL connection error ONLY when I test my rails app (localhost:3000) on chrome. It works on firefox

I'm following Michael Hartl's Rails Tutorial, and for some reason, I am unable to test the sample app on Google Chrome. I test it by first running the rails server, then going to "localhost:3000" on the browser. When I run the rails server, and go to localhost:3000 on Firefox, it works fine and I can use the app. When then on Chrome, I get:
"SSL connection error
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error."
In CMD (I use windows 7), after I run the rails server, and I attempt to go to localhost:3000, I get these errors:
14:22:19] INFO WEBrick 1.3.1
14:22:19] INFO ruby 1.9.3 (2012-02-16) [i386-mingw32]
14:22:19] INFO WEBrick::HTTPServer#start: pid=3064 port=3000
14:22:48] ERROR bad URI `2r?f?\x06\x01\x1Akh/'f??\x10'?j?<\x00\x00H?'.
14:22:48] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x02Q"\x7F?\x18??#?X?F???#K???\x17?#?e??4?k`?\x00\x00H?'.
14:22:49] ERROR bad URI `?'.
14:22:49] ERROR bad URI `??x\x1F?\x06??M??IL?C\x00\x00*\x00?\x00?\x00?\x009\x008\x00?\x005\x00E\x00D\x00f\x003\x002\x00?\x00A\x00\x05\x00\x
I had the same problem. As #looseseal_90 said in comments, you should try to clear the cookies and reload the page.
(I know that everyone can read a comment, but it would be better the question to have the answer :-)

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?

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"))

Resources