root can't bind port 80
On a linode I'm trying to run the darkhttpd web server for my website. For context,
darkhttpd is a small http server I'm trying to use for a static site. If darkhttpd is not sophisticated enough to use with Linode, I am willing to switch to a static Apache or nginx or node server.
When I run the darkhttpd server as root, it fails to bind port 80. Some calls to
nc showed me I need to specify the ip address as well. So I determined the command should be something like
darkhttpd /path/to/wwwroot --port 80 --addr my.linodes.ip.address.
When I run this as root, I get an error:
darkhttpd: bind(port 80): Permission denied
When I set the port to 8080, it works as expected.
Does anyone have any tips to fix this?
✓ Best Answer
I had been using a version of darkhttpd built by the guix package manager because it isn't in the default apt repositories configured by linode. I decided to try building darkhttpd myself, and it works now. I appreciate the help.
If you run it as root can you bind to port 80 (are you trying to set something to listen on a port less than 1024 as a non-root user)?
You said you were running as root I guess. Is there something already listening on port 80? Something like
netstat -tulpn|grep 80
@millisa I checked before posting this question, but I'll check again.
Here's what it outputs without the grep filter:
[email protected]:~# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 399/sshd
tcp6 0 0 :::22 :::* LISTEN 399/sshd
As I mentioned, I used
nc to verify I need to specify the ip address. Specifically, I used
nc -l -p80 126.96.36.199 and that works fine.