0

I've got a rails 4 application and I want to run it with SSL on webrick. what do I have to do?

I've added the ssl certificate for the domain and startet like this

bundle exec rails s -e production -p 3001 --binding=0.0.0.0

Now I got this error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at  to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at domain.de Port 443

Thanks

Directives set for Apache HTTPS

ProxyPreserveHost On
ProxyRequests On
ServerName domain.de
ServerAlias *.domain.de
ProxyPass / https://subdomain.domain.de:3001/
ProxyPassReverse / https://subdomain.domain.de:3001/
SSLEngine on
Felix
  • 5,452
  • 12
  • 68
  • 163
  • 1
    Looks like a dupe of http://stackoverflow.com/questions/3640993/how-do-you-configure-webrick-to-use-ssl-in-rails?lq=1 I'd vote to close, but the bounty prevents close votes which seems a misfeature. – Conspicuous Compiler Jun 17 '16 at 16:10

2 Answers2

5

Most people solve this by switching from webrick to thin (or even better, unicorn/puma/passenger). I don't think webrick is designed to run in production.

You could also terminate SSL at apache so that webrick only handles http. (Also, assuming Apache is running on the same box, you don't need to bind to 0.0.0.0. Localhost will do, and binding to an external IP sounds like a security vulnerability.)

If you really want to keep webrick and have it handle SSL, you change bin/rails as described in this other answer.

Community
  • 1
  • 1
Paul A Jungwirth
  • 23,504
  • 14
  • 74
  • 93
  • When my app runs properly with webrick does it also run properly with passanger? and do you have a short tutorial how to install and rund the app with passanger? – Felix Jun 17 '16 at 16:27
  • I run the application now with passanger but got en error – Felix Jun 17 '16 at 17:12
  • error is the same as bevore. Added my https directives for apache above – Felix Jun 17 '16 at 17:13
0

To use ssl just provide this in application.rb

config.force_ssl = true

Webrick for production is not recommended.Right now the best and easiest way to deploy in production is using nginx with passenger or Puma .

Nginx with Phusion Passenger

You can checkout the official documentation here it is very simple and step wise process .

Gem for Passenger

gem "passenger", ">= 5.0.25", require: "phusion_passenger/rack_handler"

Nginx with Puma

Install Puma gem add this in your Gemfile

gem "puma"

Create a Procfile in your applications root directory. Procfile for simple puma

web: bundle exec puma -C config/puma.rb

goto/create config/initializers/puma.rb

edit the value right next to worker to match with your server cores.This is how my file looks.

workers 2 #Change this to match the number of cores in your sever.My server has 2 cors
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

Nginx file configuration

server {
    listen 80;
    listen 443 ssl;

    server_name servername.com;

    ssl_certificate /root/cert_chain.crt;
    ssl_certificate_key /root/mycert.key;

    # Tell Nginx and Passenger where your app's 'public' directory is
    path to your apps public folder

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /root/.rbenv/shims/ruby;

    # vary encoders

   gzip on;
   gzip_min_length  1100;
   gzip_buffers  4 32k;
   gzip_types    text/plain application/json application/x-javascript text/xml text/css text/javascript;
   gzip_vary on;

}
Lalit Yadav
  • 889
  • 9
  • 16