How to run local Rails

server outside of local network with ssl

Hash tags: ssl https localhost

Sometimes for test purposes, it is necessary to run dev server with ssl enabled. In my case, I had to test my paypal webhooks implementation and it was required by paypal to have https in url root to hook my system up with webhooks:
paypal dashboard

Here is what we can do about it:

1) Navigate terminal to your rails project location. 
2) Generate certificate-key pair bundle.  It will ask questions but it's not required to answer them. Use the following command to actually generate the pair.
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt
3) Now there are two ways to go with. 
  a) - use thin server. this was my solution. for some reason, it works better with my chrome. To install it add :
group :development do
  gem 'thin'
run bundle install. After it's done to run the server with our created cert and key pair use starter command:
thin start –ssl –ssl-key-file localhost.key –ssl-cert-file localhost.crt
  b) Use puma server.  With cl use: 
rails s -b 'ssl://localhost:3000?key=localhost.key&cert=localhost.crt'
In case you want to add it to rubymine:
Screen Shot 2019-08-31 at 11.53.52 PM.png 46.4 KB

Screen Shot 2019-08-31 at 11.54.25 PM.png 73.9 KB

Screen Shot 2019-08-31 at 11.54.42 PM.png 507 KB

Ok now if we start ether of servers above and access
https://localhost:3000 we will be able to run in with fake ssl cert:

Screen Shot 2019-08-31 at 11.57.54 PM.png 627 KB

If you ran puma notice that now it has line with ssl:
Screen Shot 2019-08-31 at 11.58.20 PM.png 102 KB

Ok, this all looks good, but! What if we need to access our localhost from outside of our local network? Well here is what we can do:

1) Log in to your home router and find port forwarding settings:
Screen Shot 2019-09-01 at 12.02.16 AM.png 141 KB

2) #3 - puma that is my port forwarding settings for puma server.  To make this all work we need to transfer 443(ssl) -> 3000 port. 443 is our outside port and 3000 our puma rails. is my server IP address. Here is another more detailed screenshot:
Screen Shot 2019-09-01 at 12.04.59 AM.png 27.2 KB

3) Now we need to know our public IP address. Easy to check in google by asking what is my ip.
4) Accessing localhost from outside by using public ip:
Screen Shot 2019-09-01 at 12.10.54 AM.png 233 KB

Making this all work can be a bit wavy. Puma gave me a lot of trouble with ssl so I use thin in case I need to test paypal and regular puma when I need to test regular stuff. Hopefully it will save someone time.