├── README.md └── images ├── header.jpg ├── https-fail.png ├── https-success.png └── it-works.png /README.md: -------------------------------------------------------------------------------- 1 | # How to use self-signed SSL certificate for local development on Rails 2 | 3 |

4 | 5 |

6 | 7 | SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. 8 | 9 | ## In short 10 | 11 | ```bash 12 | $> openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt 13 | $> rails s -b 'ssl://localhost:3000?key=localhost.key&cert=localhost.crt' 14 | ``` 15 | 16 | ## Why you may need SSL in development? 17 | 18 | Check this [tweet](https://twitter.com/getify/status/1023202051902373888) to find the answer. 19 | 20 | Short summary: 21 | 22 | - No mixed-content warnings 23 | - Using features / third-party integrations that require SSL 24 | - URL logic (routing, history, redirects) 25 | 26 | ## Let's rock 27 | 28 | Firstly, start the server and make sure that the HTTPS connection is not established. 29 | 30 | ```bash 31 | $> rails s 32 | 33 | => Booting Puma 34 | => Rails 5.2.3 application starting in development 35 | => Run `rails server -h` for more startup options 36 | Puma starting in single mode... 37 | * Version 3.12.1 (ruby 2.5.1-p57), codename: Llamas in Pajamas 38 | * Min threads: 5, max threads: 5 39 | * Environment: development 40 | * Listening on tcp://localhost:3000 41 | Use Ctrl-C to stop 42 | ``` 43 | 44 | Browser: 45 | 46 |

47 | 48 |

49 | 50 | Puma logs: 51 | 52 | ```bash 53 | --- 54 | x: HTTP parse error, malformed request (): # 55 | --- 56 | ``` 57 | 58 | ## Step one: generate the cert 59 | 60 | ```bash 61 | $> openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt 62 | ``` 63 | 64 | > NOTE: you can change days parameter (365) for any number to affect the expiration date. 65 | 66 | You will be provided with some information fields to fill in about country key, email, etc. However, you can skip this step. This command will create two new files `localhost.key` and `localhost.crt` in the current directory. You can move these files anywhere. 67 | 68 | ## Step two: run a server with the certificate 69 | 70 | ```bash 71 | $> rails s -b 'ssl://localhost:3000?key=localhost.key&cert=localhost.crt' 72 | 73 | => Booting Puma 74 | => Rails 5.2.3 application starting in development 75 | => Run `rails server -h` for more startup options 76 | Puma starting in single mode... 77 | * Version 3.12.1 (ruby 2.5.1-p57), codename: Llamas in Pajamas 78 | * Min threads: 5, max threads: 5 79 | * Environment: development 80 | * Listening on ssl://localhost:3000?key=localhost.key&cert=localhost.crt 81 | Use Ctrl-C to stop 82 | ``` 83 | 84 | Browser: 85 | 86 |

87 | 88 |

89 | 90 | > NOTE: Firstly, click 'ADVANCED' (i) and then 'Proceed to localhost (unsafe)' (ii). 91 | 92 |

93 | 94 |

95 | 96 | Puma logs: 97 | 98 | ```bash 99 | ... 100 | 101 | Started GET "/" for ::1 at 2019-04-16 16:02:11 +0300 102 | Processing by Rails::WelcomeController#index as HTML 103 | Rendering rails/templates/rails/welcome/index.html.erb 104 | Rendered rails/templates/rails/welcome/index.html.erb (2.6ms) 105 | Completed 200 OK in 6ms (Views: 4.7ms | ActiveRecord: 0.0ms) 106 | 107 | ... 108 | ``` 109 | 110 | ## License 111 | 112 | Copyright © 2015-2019 Codica. It is released under the [MIT License](https://opensource.org/licenses/MIT). 113 | 114 | ## About Codica 115 | 116 | [![Codica logo](https://www.codica.com/assets/images/logo/logo.svg)](https://www.codica.com) 117 | 118 | We love open source software! See [our other projects](https://github.com/codica2) or [hire us](https://www.codica.com/) to design, develop, and grow your product. -------------------------------------------------------------------------------- /images/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codica2/rails-puma-ssl/eb9da7f0c142f858bbee6cad006cd4baec893a8f/images/header.jpg -------------------------------------------------------------------------------- /images/https-fail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codica2/rails-puma-ssl/eb9da7f0c142f858bbee6cad006cd4baec893a8f/images/https-fail.png -------------------------------------------------------------------------------- /images/https-success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codica2/rails-puma-ssl/eb9da7f0c142f858bbee6cad006cd4baec893a8f/images/https-success.png -------------------------------------------------------------------------------- /images/it-works.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codica2/rails-puma-ssl/eb9da7f0c142f858bbee6cad006cd4baec893a8f/images/it-works.png --------------------------------------------------------------------------------