Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run Rails with HTTPs locally for testing?

Our dev envs use HTTP, prod uses HTTPS, this is causing issues that we can't reproduce locally with are HTTPS related.

How can I run rails with SSL locally for testing purposes? Is there a Webrick config?

Thanks

like image 291
AnApprentice Avatar asked Dec 22 '11 20:12

AnApprentice


People also ask

How do I run HTTPS on a Rails server?

To serve a Ruby on Rails application via HTTPS, there are three steps that you need to follow: Obtain an SSL certificate. Configure the web server to use the SSL certificate. Configure the Ruby on Rails application for HTTPS.


2 Answers

you should to use thin to do it:

$ sudo apt-get install thin

And add this line in config/application.rb

config.force_ssl = true

Then run app on thin with command line:

$ thin start --ssl
like image 85
Hieu Le Avatar answered Sep 30 '22 00:09

Hieu Le


I think the question here is specific to the Rails 'testing' environment, which might mean rspec, and if so, this gist by jaikoo was what worked for me:

https://gist.github.com/jaikoo/daf88024b8de1cf9339b

With respect to the 'development' environment, ultimately I used thin, which I didn't really want to, but the best write-up of that I saw was this post by Keyur Gohil:

https://blog.botreetechnologies.com/enable-ssl-in-developement-using-thin-2a4bd1af500d

Though I put it in a batch file and added -D -V and made sure it ran on a different port:

#!
#  Sets up the use of SSL in development
#
# https://www.devmynd.com/blog/rails-local-development-https-using-self-signed-ssl-certificate/
#
bundle exec thin -D -V start -a localhost -p 3001 --ssl --ssl-key-file ~/development/apps/localhost_ssl_tsl_keys/localhost.key --ssl-cert-file ~/development/apps/localhost_ssl_tsl_keys/localhost.crt
like image 35
codenoob Avatar answered Sep 30 '22 00:09

codenoob