My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


Using Caddy to Develop RoR

Working on a few projects in rails and I wanted to do something where I could load the site in the browser with a tld and an ssl certificate like people. So going to https://conflict.dev would take me to my local runing dev server for my conflict app. And if I had other things I was working on at the same time, I wanted them to also be able to be loaded in the same way. Oh, and I need them to have ssl certificates so I can test with that as well!

I read a few posts and came to the conclusion that Caddy and a reverse proxy are what I want. In short, I run Caddy and have it reverse proxy my site on port 3000 and publish it to 80 and 448.

Here are the steps that I took to accomplish this:

First thing I want to do is create some signed certificartes in my site root.

mkcert domain.tld

Then I need to make sure I am loading puma and my rails apps on distinct ports. I created a rake task called local for this

desc "launching the rails server on a set port"
task :local do
sh  "rails s -p 3040 --daemon"
sh  "caddy start"
end

As you can see, I am starting puma on port 3040 here and also starting Caddy.

For that last line to work I need to create a file in my project root Caddyfile

domain.tld
reverse_proxy localhost:3040
tls domain.tld.pem domain.tld-key.pem

This sets up the domain and the ssl certificates for the site.

In order to make sure that rails security recognizes your new domain you will need to edit config/environments/development.rb Just add the line:

config.hosts << "domain.tld"

The last thing that we need to do is setup the hosts records. It’s as easy as adding 127.0.0.1 domain.tld

Now, to get this all up and running, I just run rake local and all the services are spun up and I can goto my site in the browser as if it were a live site!

© 2024 David Duggins. All rights reserved.