Running in prod
So, I deployed beacon and live admin following the guides. Everything works ok.
But when I do a MIX_ENV=prod mix phx.server' everything is messed up. I understand (vaguely) why you needed to add the two new endpoints (proxy and blog), but it would be extremely helpful to have a small doc explaining how to run it in prod. Because it completely modified my existing configuration for the prod environment, adding a mix of httpandhttps`, adding some random ports, binding to all the interfaces while my initial config was 127.0.0.1 and so on and so fort.
Thanks!
Hi Dan! The ProxyEndpoint task(s) should work just fine in production. We took great care (several weeks of testing) to ensure we covered as many different edge cases as possible, so it would "just work" after running the task. It sounds like you may have encountered some other edge case which we missed - so let's troubleshoot together and we can find a permanent fix for this issue. Probably the relevant details will be in your /config/runtime.exs but feel free to share any other code that you think might be non-standard in your app!
Hi, Andrew!
Thank you for your quick response. Let me try to describe what is happening. I start with this config in `runtime.exs':
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "5000")
config :test, TestWeb.Endpoint,
url: [host: host, port: 5000, scheme: "http"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {127, 0, 0, 1},
port: 5000
],
The background rationale: I'm running quite a few apps on a hetzner machine, nginx as proxy, each app running in a tmux session. It's my test machine. After I install beacon following the instruction in the guides, the config is changed like this:
config :test, TestWeb.Endpoint,
url: [host: host, port: 5000, scheme: "http"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {127, 0, 0, 1},
port: 5000
],
secret_key_base: secret_key_base
config :test, TestWeb.ProxyEndpoint,
check_origin: {TestWeb.ProxyEndpoint, :check_origin, []},
url: [port: 443, scheme: "https"],
http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
secret_key_base: secret_key_base,
server: !!System.get_env("PHX_SERVER")
config :test, TestWeb.TestEndpoint,
url: [host: host, port: 8793, scheme: "https"],
http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: 4111],
secret_key_base: secret_key_base,
server: !!System.get_env("PHX_SERVER")
How I reached this: generate a fresh app called test, install igniter, install beacon and liveadmin via the mix igniter command line, generated a beacon site at /blog.
What is happening: as you said, site responds at http://example.com:5000. Now when I access 'http://example.com:5000/blog`, the default auto-generated page renders, but the 'we can't find the internet' socket message pops up. And this is what I have in the console logs:
19:52:28.465 [info] Access TestWeb.Endpoint at http://example.com:5000
19:52:57.991 [warning] Connection that looks like TLS received on a clear channel
19:52:57.995 [warning] Connection that looks like TLS received on a clear channel
19:53:01.687 request_id=GCz7C0PJoa4syQ4AAARk [info] GET /
19:53:01.729 request_id=GCz7C0PJoa4syQ4AAARk [info] Sent 200 in 42ms
19:53:08.946 request_id=GCz7DPSMJs2QKBEAAAAG [info] GET /blog
19:53:08.975 [info] Beacon - loading LiveData for test
19:53:09.053 [info] Beacon - loading Layoutd4056537-4086-4b21-9529-cbcee905880b for test
19:53:09.079 request_id=GCz7DPSMJs2QKBEAAAAG [info] Sent 200 in 132ms
19:53:09.097 request_id=GCz7DP2WsHOQKBEAAABm [info] GET /blog/__beacon_assets__/css-cda41c3e5794a12244b2a0eef35ca239
19:53:09.098 request_id=GCz7DP2g7oXwYt4AACFB [info] GET /blog/__beacon_assets__/js-a8817ce4314dd947eb3cb4747f231cff
19:53:09.104 request_id=GCz7DP2g7oXwYt4AACFB [info] Sent 200 in 5ms
19:53:09.104 request_id=GCz7DP2WsHOQKBEAAABm [info] Sent 200 in 6ms
19:53:09.297 request_id=GCz7DQmEH6a0o6UAAACG [info] GET /live/websocket
19:53:09.345 request_id=GCz7DQmEH6a0o6UAAACG [warning] failed to render error page for 404.html, fallbacking to default Phoenix error page
Got:
%KeyError{key: :phoenix_live_view, term: %{:phoenix_template => "404.html", :phoenix_view => %{_: Beacon.Web.ErrorHTML}, TestWeb.Router => [], :phoenix_endpoint => TestWeb.Endpoint, :phoenix_router => TestWeb.Router, :plug_session_fetch => #Function<1.49469887/1 in Plug.Session.fetch_session/1>, :before_send => [#Function<0.106864063/1 in Plug.Telemetry.call/2>], :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_layout => %{_: false}, :phoenix_format => "html", :phoenix_root_layout => %{_: false}}, message: nil}
19:53:09.345 request_id=GCz7DQmEH6a0o6UAAACG [info] Sent 404 in 47ms
19:53:09.361 request_id=GCz7DQ1JFhUgj4wAAACm [info] GET /live/websocket
19:53:09.361 request_id=GCz7DQ1JFhUgj4wAAACm [warning] failed to render error page for 404.html, fallbacking to default Phoenix error page
Got:
%KeyError{key: :phoenix_live_view, term: %{:phoenix_template => "404.html", :phoenix_view => %{_: Beacon.Web.ErrorHTML}, TestWeb.Router => [], :phoenix_endpoint => TestWeb.Endpoint, :phoenix_router => TestWeb.Router, :plug_session_fetch => #Function<1.49469887/1 in Plug.Session.fetch_session/1>, :before_send => [#Function<0.106864063/1 in Plug.Telemetry.call/2>], :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_layout => %{_: false}, :phoenix_format => "html", :phoenix_root_layout => %{_: false}}, message: nil}
19:53:09.361 request_id=GCz7DQ1JFhUgj4wAAACm [info] Sent 404 in 322µs
19:53:09.414 request_id=GCz7DRBuBL-l3rIAAADG [info] GET /live/websocket
19:53:09.414 request_id=GCz7DRBuBL-l3rIAAADG [warning] failed to render error page for 404.html, fallbacking to default Phoenix error page
Got:
%KeyError{key: :phoenix_live_view, term: %{:phoenix_template => "404.html", :phoenix_view => %{_: Beacon.Web.ErrorHTML}, TestWeb.Router => [], :phoenix_endpoint => TestWeb.Endpoint, :phoenix_router => TestWeb.Router, :plug_session_fetch => #Function<1.49469887/1 in Plug.Session.fetch_session/1>, :before_send => [#Function<0.106864063/1 in Plug.Telemetry.call/2>], :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_layout => %{_: false}, :phoenix_format => "html", :phoenix_root_layout => %{_: false}}, message: nil}
19:53:09.414 request_id=GCz7DRBuBL-l3rIAAADG [info] Sent 404 in 264µs
And it goes on and on with the same error.
The interesting part of lsof looks like this:
beam.smp 63137 dantodor 37u IPv4 0x563a8d2f204eba03 0t0 TCP 127.0.0.1:59410 (LISTEN)
beam.smp 88640 dantodor 37u IPv4 0x22367e545cced67b 0t0 TCP 127.0.0.1:60370 (LISTEN)
beam.smp 88640 dantodor 39u IPv4 0xae6f52ea07d9b22a 0t0 TCP 127.0.0.1:60372->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 40u IPv4 0xf45d52517276f864 0t0 TCP 127.0.0.1:60373->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 42u IPv4 0x31efed73cca77567 0t0 TCP 127.0.0.1:60374->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 43u IPv4 0x7c0624fd552505d6 0t0 TCP 127.0.0.1:60375->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 44u IPv4 0x36f4454c16006ad 0t0 TCP 127.0.0.1:60376->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 45u IPv4 0x71468c3571ad2577 0t0 TCP 127.0.0.1:60377->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 46u IPv4 0x5005477079ae97e7 0t0 TCP 127.0.0.1:60378->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 47u IPv4 0xcfdc72414e2109d8 0t0 TCP 127.0.0.1:60379->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 48u IPv4 0x46e149d7f0c3bb19 0t0 TCP 127.0.0.1:60380->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 49u IPv4 0xb913f48c204d2c87 0t0 TCP 127.0.0.1:60381->127.0.0.1:5432 (ESTABLISHED)
beam.smp 88640 dantodor 50u IPv4 0x5adc0745f5ca3f57 0t0 TCP 127.0.0.1:5000 (LISTEN)
And it goes on an on with the same error. My troubles are at least two:
- I don't understand where the error comes from
- my understanding might be wrong, but I see TestWeb.Endpoint and proxyEndpoint competing for port 5000. Am I wrong?
- what actual ports are in use, because outside of 5000 from the config, any of the rest are not showing ?
Let me know if this report is detailed enough.
And thanks again!
I have been facing a similar issue in local setup as well. Maybe a recent issue. Will look into it and update my findings if they are similar as well.