Configuring http to use port 80

I’d like mopidy to listen on port 80 so users can avoid typing ‘http://musicServer:6680’, and instead just type ‘http://musicServer’. But linux only allows root to listen on ports < 1024. Is there some way to give user mopidy privileges to use port 80?

I’m running mopidy as a service. Here’s my config file:

pi@pynet ~ $ sudo cat  /etc/mopidy/mopidy.conf
[logging]
config_file = /etc/mopidy/logging.conf
debug_file = /var/log/mopidy/mopidy-debug.log

[local]
enabled = true
data_dir = /var/lib/mopidy/local
media_dir = /var/lib/mopidy/media
playlists_dir = /var/lib/mopidy/playlists


[http]
enabled = true
hostname = 0.0.0.0
port = 80

Here’s the mopidy log file

2015-11-28 22:04:27,738 ERROR [6319:MainThread] mopidy.commands: Frontend (HttpFrontend) initialization error: HTTP server startup failed: [Errno 13] Permission denied
2015-11-28 22:04:27,754 INFO [6319:MainThread] mopidy.commands: Initialization error. Exiting..

I found that you can “remap” ports using the iptables command, like so:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 6680
sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 6680

but was hoping for a more secure option, since the above allows any user access to port 80.

http://man7.org/linux/man-pages/man7/capabilities.7.html would work for granting limited access to ports, but this doesn’t work nicely as you would have to give it to python.

So I would recommend just putting a proxy in front of Mopidy, for instance nginx. Just make sure to setup proxying of the websocket correctly.