Allowed to bind port when running Scala application via SBT

I am trying to run my Scala code using SBT but I get the error below. This happens both with SBT using the command line and with IntelliJ Idea.

[error] (run-main) org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:80 org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:80 .... .... Caused by: java.net.SocketException: Permission denied 

What should I configure to allow access to the port. This happens both when trying to run on the local Mac, and on a remote Ubuntu server.

Running sbt with "sudo sbt" fixes the problem, but it is not a solution. Where can I set the permission to allow my Scala application to access port 80.

+6
source share
3 answers

The solution to this problem will depend on the operating system, and not on what SBT, Scala, or Java can do.

For example, Debian offers three different solutions , all of which can be used in other Linux distributions - two of them are options when running as root, and the third uses iptables to fake listening on port 80.

FreeBSD can completely disable the lower port restriction, and Solaris can do this for each user and port, as described (for both) here .

+4
source

Running sbt with "sudo sbt" fixes the problem, but it is not a solution. Where can I set the permission to allow my Scala application to access port 80.

I think this is your only solution. Only privileged applications can communicate with ports under 1024.

Maybe it’s more convenient for you to manage the http proxy server on port 80 (only proxies with root privileges) or have some kind of ipfilter rule that redirects incoming port 80 to port 8080? See also this answer .

+4
source

You might want to take a look at commons-daemon [1] and its binary jsvc. This allows you to run as root and drop after some tasks. The tasks here may be port binding.

[1] http://commons.apache.org/daemon/

+2
source

Source: https://habr.com/ru/post/907749/


All Articles