peppy
Apache2 / Phoenix: How To Set Up Reverse Proxy?
Starting with a fresh install of Phoenix on a Ubuntu 20.04 server with Apache2, what are the specific steps for setting up a reverse proxy (what should the block of code in apache be exactly? what do I edit in the phoenix app files?)
By default, Phoenix runs fine on: https://www.mysite.com:4000/
I want it to run on: https://www.mysite.com/ex/ (without the port 4000 in the URL)
The “Welcome To Phoenix” page and all css/js/image files should load, the live view frame should load and the sockets should work with no errors.
Right now, I have something like the following in my Apache config:
<VirtualHost *:443>
ServerName www.mysite.com
ServerAlias mysite.com
<Location /ex/>
ProxyPass http://127.0.0.1:4000/
ProxyPassReverse http://127.0.0.1:4000/
</Location>
</VirtualHost>
In Phoenix, I edited config/config.exs to something like this:
config :exchat, ExchatWeb.Endpoint,
url: [host: "localhost", path: "/ex"],
At the moment, the phoenix page on the website (css/js/images) loads up fine, but the sockets aren’t working. In the console, I’m seeing repeating errors like:
WebSocket connection to 'wss://www.mysite.com/socket/websocket?token=undefined&vsn=2.0.0' failed
WebSocket connection to 'wss://www.mysite.com/ex/phoenix/live_reload/socket/websocket?vsn=2.0.0' failed
…
Thanks
Most Liked
derek-zhou
Running an application involve phoenix sockets not at the root path is tricky. Do you really want to do that? In the old time, people do this to save a separate https cert. now that letsencrypt is free, most people will just make another sub domain and build a virtual host.
If you really want to do this, check your app.js for the socket connection statement. You may want to fix that to your path prefix.
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








