Hi there, I’m working through my first release with elixir/phoenix. I’ve built a release with distillery and found that it crashes when I start it since it’s trying to access port 80 and linux restricts ports under 1024. Starting and running the server as root would work but I’m not going to do that.
In the past, working with other stacks the solutions I’ve used have been:
Use apache/nginx which do have elevated permissions to start but then drop them.
Use rails or node (or what ever I’m building with) on a higher port and run nginx in front as a proxy. (though Jose has said there’s usually no need to run Phoenix behind nginx)
Use IP tables (and break ipv6)
Based on what I’ve seen online, the best solution may be to use setcap to give the binary permission to use the port. However I’ve tried that on erl, mix, iex and elixir and still can’t get the server to bind to port 80.
$ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/lib/erlan/bin/erl $ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/local/lib/elixir/bin/mix $ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/local/lib/elixir/bin/iex $ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/local/lib/elixir/bin/elixir $ MIX_ENV=prod PORT=80 mix phoenix.server 06:10:14.161 [error] Failed to start Ranch listener Myapp.Endpoint.HTTP in :ranch_tcp:listen([port: 80]) for reason :eacces (permission denied)