I'm working on an app currently and I attempted to replace my webserver WEBrick with puma. The application is currently deployed with Heroku. Also, while doing this I wanted to be able to run my rails s with production. To my understanding, I would need to set the SECRET_KEY_BASE key in my secret.yaml file. I did this while also setting up a SECRET_TOKEN in heroku. To make a long story short, I actually reverted back to WEBrick webserver. But now, when I run rails s production or development, I get the following:
=> Booting WEBrick
=> Rails 4.2.5.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-04-27 13:40:57] INFO WEBrick 1.3.1
[2016-04-27 13:40:57] INFO ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
[2016-04-27 13:40:57] INFO WEBrick::HTTPServer#start: pid=24061 port=3000
When trying to load the page at https://localhost:3000/ I get the following errors in terminal:
[2016-04-27 13:41:09] ERROR bad URI `]n?Q2}N?<\x01H\x00\x00\x1C?+?/̨̩?\x14?\x13?'.
[2016-04-27 13:41:09] ERROR bad URI `dU?\x00\x00\x1C?+?/̨̩?\x14?\x13?'.
[2016-04-27 13:41:09] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03}??4??CN??\x02\x04?4?\x17??\ea??u%?\x06?yڔ\x13?\x00\x00\x1C?+?/̨̩?\x14?\x13?'.
[2016-04-27 13:41:09] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03????3?W\x14kt??0M\x1A#U?"u?Ä??qj?]}??\x00\x00\x1C?+?/̨̩?\x14?\x13?'.
[2016-04-27 13:41:09] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03?f\x1E?V?4?'.
[2016-04-27 13:41:09] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03??C?ݔ\x01\r?OS#?S??Ej?\\\x15\r\x17k\x0Ep?\x1C?"?F\x00\x00\x1C?+?/̨̩?\x14?\x13?'.
And the following in my DOM:
This site can’t provide a secure connection
localhost sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
So obviously I did something when setting up the SECRET_TOKEN/SECRET_KEY_BASE because before it was working and now not a single project of mine can run the rails server. I understand that this is dealing with SSL, but I am unsure where to begin or how to fix this. I have tried and read a lot and have yet to have some luck.
SIDE NOTE: I have created a brand new rails project from scratch and simply tried to run rails s. I have had the same issue. As I commented below, I was having the same issue when trying to run puma as my webserver. I now cannot run a local server on ANY project of mine. This leads me to believe that I have messed something up that applies to my system.
Thank you for any time taken/spent to help me.
FIXED:
Okay, so for whatever reason(something I did I'm sure), when I attempted to visit localhost:3000 it would take me to -> https://localhost:3000 which, as you stated, could not be handled by WEBrick unless configured to do so. My address bar continued to force HTTPS, even if I tried visiting http://localhost:3000. After I cleared my cookies/history...everything is working. I appreciate your help.
Related
i am trying to debug rails app - unicorn server.
I've tried following:
1) I tried to start the server on localhost (externally, not with RubyMine) and set some break points. I can see my server when trying to "attach to process". It can attach to process but when i call some REST WebService it won't stop on this method in controller.
2) I tried to run the server from Debugger in RubyMine, the server starts, but when i call some REST WebService it won't stop on this method in controller.
How to debug the Rails App on Mac OS (localhost, unicorn)?
The Rails App ist only API. I want to debug my api calls.
Problem solved:
- i was using pow and it was redirecting to some url and not directly to localhost:3000. Once i converted the requests to use localhost:3000 instead of pow URL xxx.something.test debugger fired up.
I don't have rubymine but this worked for me:
install "pry": https://github.com/pry/pry
start unicorn on your local env:
bundle exec unicorn -c config/unicorn.rb
make sure you're listening to a valid port (in your confic/unicorn.rb):
listen 3000
add
binding.pry
in your code wherever you want a breakpoint
go to:
0.0.0.0:3000
What could possibly be wrong? I run this file:
require 'sinatra'
get '/' do
"Just Do It"
end
Server starts up:
== Sinatra (v2.0.0) has taken the stage on 3000 for development with backup from Thin
Thin web server (v1.7.1 codename Muffin Mode)
Maximum connections set to 1024
Listening on 127.0.0.1:3000, CTRL+C to stop
(I set the address and port because it is what I have in my vagrantfile.
However I get nothing, either in Chrome or Firefox. I've tried various config.ru's and changed the file above to an ru extension to try rackup but that hasn't worked either.
I have uninstalled and reinstalled the Mustermann and Sinatra gems and made sure I had the gems that are required in base.rb.
Any ideas?
In Rails 4 from config > environments > production.rb by changing: config.consider_all_requests_local= true, Devs can turn on Full error reports on production.
Is it possible to whitelist some IP-adresses so Full error reports is true for these IPs while for rest would be false.
I know I can read the production logs from server logs, but its a hassle log in to server and remember the correct path and not to mention its readability is very poor.
I don't think Rails will allow you to do that. However, you can use better_errors gem to whitelist IP's for logs
When running the command
rails server
instead of the server running, I am getting the following output:
Why is the server not running?
It looks like you're not executing rails server inside a rails app directory.
Use rails new app_name and change directory into that app and run rails server again.
I searched the internet for a "Hello, World" type program for Webrick in Ruby, but could not find anything that worked. I found this guide on SO but for the life of me could not get it to work.
Consulting the Ruby Documentation for Webrick led me to some code snippets that got me going in the right direction. There were no easy-to-follow tutorials so I wanted to add my answer on SO.
I was using Ubuntu 14.04 without Apache or Nginx and wanted my server for a virtual host. Webrick by default does not respond to requests concurrently but for me this was a plus in addition to its small footprint. I was hoping to get it working without the Rails framework for an even lighter footprint.
To get started, I installed Ruby with the Ubuntu package manager. If you are using CentOS or another Linux distribution, you can adapt this step to your particular package manager. Also make sure port 80 is open on your web server. It's possible to get SSL with Webrick but I chose not to at this point.
sudo apt-get install ruby
Here is the script which I named myapp.rb that I am using. I placed it /var/www/myapp. Ideally, I think it should not be in document root. You should also create a special user and group just to run the script to improve security (I have not outlined those steps here)
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 80,
:SSLEnable => false,
:DocumentRoot => '/var/www/myapp',
:ServerAlias => 'myapp.example.com')
server.mount_proc '/' do |req, res|
res.body = 'Hello, world!'
end
trap 'INT' do server.shutdown end
server.start
The require statement above tells Ruby to include the Webrick classes when running the program. The second line of the script creates an instance of Webrick with the following options:
Use Port 80
Disable SSL
Set the document root to /var/www/myapp
Set the Server Alias to myapp.example.com
Of course, you'll have to configure your particular domains DNS'. The server.mount_proc is telling Ruby to serve the response, "Hello, world" at document root. I think you can specify a subdirectory there if you life. The Ruby Webrick documentation above has information on that.
The line that begins with trap means that the web server can be stopped with Ctrl-C. To start the script I typed the following at the SSH command line:
ruby myapp.rb