Doerge
Multiple domains on a single Phoenix app
I want to serve multiple domains in a single Phoenix app.
After Googling I landed on this:
Which recommends setting
config :my_app, MyAppWeb.Endpoint,
url: [host: nil]
however the docs here:
don’t mention that.
I opened a bug here: Missing docs for Endpoint url: [host: nil] behaviour · Issue #3907 · phoenixframework/phoenix · GitHub
which revealed that, the behavior is not intentional, and should not be relied on.
My questions are now:
- How do I enable multiple domains?
- Can I just point my DNS to my server, and then most things work? Except for url generation in emails etc? When and where do I fall off the map?
Marked As Solved
Doerge
Thanks for clarifying! I was unsure of if :url in the endpoint was used for some sort of validation/security.
I deployed now, and everything seems to be working after I have deployed a test with:
config :my_app, MyAppWeb.Endpoint,
url: [host: "mydomain1.com"],
force_ssl: [host: nil],
check_origin: [
"https://mydomain1.com",
"https://mydomain2.com"
]
Also Liked
LostKobrakai
For :force_ssl it’s documented. For :url it should work automatically for any domain if you use a conn as the first param for the url generating helpers. What you set as setting on the endpoint is just the default to fall back for other inputs to those helpers, which don’t have access to a current request.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









