Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create doc/guide for multiple domains hosting with Beacon #393

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions guides/deployment/multiple_domains_hosting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Multiple Domains/Tenants

You can host multiple domains or subdomains with Phoenix by using the `:host` option of the scope function in your router:

`:host` - a string or list of strings containing the host scope, or prefix host scope, ie "foo.bar.com", "foo."

```elixir
# match admin. subdomain
scope "/", MyAppWeb, host: "admin." do
live "/", AdminLive, :new
end

# match example.com, and "example2.com"
scope "/", MyAppWeb, host: ["example.com", "example2.com"] do
live "/", LandingLive, :new
end

# match my-example.org
scope "/", MyAppWeb, host: "my-example.org" do
live "/", HomeLive, :new
end
```

## Multiple Domains/Tenants hosting with BeaconCMS

So if you need to host multiple domains or subdomains with Beacon, you can use the same `:host` option:

Here's another example, but now using Beacon:

```elixir
scope "/", host: "demo.org" do
alexandrexaviersm marked this conversation as resolved.
Show resolved Hide resolved
pipe_through :browser

beacon_site "/demo", site: :demo
end

scope "/", host: "blog.com" do
alexandrexaviersm marked this conversation as resolved.
Show resolved Hide resolved
pipe_through :browser

beacon_site "/blog", site: :blog
alexandrexaviersm marked this conversation as resolved.
Show resolved Hide resolved
end

scope "/admin" do
alexandrexaviersm marked this conversation as resolved.
Show resolved Hide resolved
pipe_through :browser
beacon_live_admin "/"
end
```

You also need to pass the `:check_origin` option when configuring your
endpoint explicitly outlining which origins are allowed:

Edit `config/runtime.exs` and edit the following config inside `config :my_app, MyAppWeb.Endpoint, ...`:

```elixir
check_origin: [
"https://beacon-demo.com/",
"https://demo.org",
"https://blog.com"
],
```
Loading