After finishing Chapter 11 of the Rails Tutorial and partway through Chapter 12, I got the following error when running rails s
:
HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.
In short, it’s telling me to access using https
even in the local environment. So, I’ll modify my setup to enable https
connections in the local environment.
I’ll use mkcert, which makes it easy to create self-signed certificates.
Installing mkcert:
$ brew install mkcert
$ brew install nss # Also needed if you use Firefox
Creating the certificate:
$ mkcert -install
$ mkcert example.com
# Certificates are generated in the current directory
$ ls -l ./*.pem
-rw------- 1 tofu staff 1708 4 22 20:00 ./example.com-key.pem
-rw-r--r-- 1 tofu staff 1549 4 22 20:00 ./example.com.pem
Modify config/puma.rb
to reference the certificates we just created:
# config/puma.rb
cert = "/Users/name/example.com.pem"
key = "/Users/name/example.com-key.pem"
ssl_bind "0.0.0.0", 9292, cert: cert, key: key
Finally, run pumactl start
instead of rails s
, and access https://localhost:9292/.