Trying to build a white label phx app denoted by subdomains and mix phx.gen.secret

I’ve been trying to generate a self signed cert that I can use for local development that supports the primary domain (ie localhost) and any number of subdomains (ie foo.localhost, bar.localhost)

I’ve hit a wall when it comes to generating a cert that will work for my needs.




I’ve tried a number of ways to try and generate the cert but have failed every time to get both the domains to work. I also since forgot which I’ve tried so I’m hay to try again and document here for others.

Any help is appreciated

PS: I should also note this white label app is for free hosting for elixir user groups.
https://github.com/PDX-Elixir-Group/elixir.group

best.
– Josh

1 Like

I have found that you can specific multiple domains with
mix phx.gen.cert localhost foo.localhost

And while this will work for the short term, I’m still gonna look for the wildcard equivalent.

Generate them on your own instead of relying on Phoenix. Makefile for that:

NAME     = localhost
DOMAIN   = *.localhost

KEY      = ${NAME}.key
SIGN_REQ = ${NAME}.csr
CERT     = ${NAME}.crt

SUBJECT = "/C=US/ST=Connecticut/O=/localityName=New Haven/commonName=$(DOMAIN)/commonName=localhost/organizationalUnitName=/emailAddress=/"

all: ${CERT}

clean:
	$(RM) -rf ${KEY} ${CERT} ${SIGN_REQ}

verify: ${CERT}
	openssl x509 -noout -text -in $<

${KEY}:
	openssl genrsa -out "$@" 2048

${SIGN_REQ}: ${KEY}
	openssl req -new -sha256 -subj $(SUBJECT) -key "$<" -out "$@" -passin pass:""

${CERT}: ${SIGN_REQ} ${KEY}
	openssl x509 -req -days 365 -in "${SIGN_REQ}" -signkey "${KEY}" -out "$@"

.PHONY: all clean verify
3 Likes

I think the issue is with the wildcard dns not with the way its being generated.