Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied to bind to port when running Scala application via SBT

Tags:

scala

sbt

netty

I'm trying to run my Scala code with SBT, but 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 do I configure to allow port access. This happens both when I try to run on my local Mac and on my remote Ubuntu server.

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

like image 570
Jack Avatar asked Feb 06 '12 07:02

Jack


2 Answers

The solution to this problem will depend on the operating system, not on anything that SBT, Scala or Java might do.

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

On FreeBSD one can disable the low port limitation entirely, and Solaris can do so per-port-and-user, as described (for both) here.

like image 181
Daniel C. Sobral Avatar answered Nov 14 '22 22:11

Daniel C. Sobral


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

I think that is your only solution, though. Only privileged applications can bind to ports under 1024.

Maybe you are more comfortable with running an http proxy on port 80 (only the proxy as root), or have some ipfilter rule that re-routes incoming port 80 to port 8080 ? See also this answer.

like image 24
Thilo Avatar answered Nov 14 '22 22:11

Thilo