Hello alltogether,

it's a really silly question actually, but I just can't figure it out. I want to write a simple server, that serves the HTTP-protocoll (Port 80). The connection does work, when I let the programme run on port 8080, but Mac OS prohibits the connection on port 80. What can I do?

Many, many thanks
Simon

PS I thought I posted this thread yesterday already, but can't find it anymore. So if the old thread still exist, please delte this one.

Dani AI

Generated

As noted, your server already works on 8080 and pointed toward the system-level restriction you hit. Here are practical, safe ways to get HTTP on port 80 without guessing which macOS version you have — pick the one that fits your setup.

One-line port-forward (no need to run your app as root)

# forward external interface en0 -> local server 127.0.0.1:8080
echo "rdr pass on en0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080" | sudo pfctl -f -
sudo pfctl -e

# to stop pf rules:
sudo pfctl -d

Use lo0 instead of en0 if you only need localhost redirection (127.0.0.1). Make the rule persistent by adding it to /etc/pf.conf or an anchor.

Run as a proper daemon via launchd (safe for production)

# save as /Library/LaunchDaemons/com.example.myserver.plist (owner root:wheel, chmod 644)
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
  <key>Label</key><string>com.example.myserver</string>
  <key>ProgramArguments</key>
  <array><string>/usr/local/bin/myserver</string></array>
  <key>RunAtLoad</key><true/>
  <key>UserName</key><string>root</string>
  <key>KeepAlive</key><true/>
  <key>StandardOutPath</key><string>/var/log/myserver.out</string>
  <key>StandardErrorPath</key><string>/var/log/myserver.err</string>
</dict>
</plist>

# load it
sudo launchctl load -w /Library/LaunchDaemons/com.example.myserver.plist

This lets launchd start the binary with root privileges so it can bind port 80; drop privileges inside the process after binding if possible.

Reverse-proxy (recommended if you want unprivileged app)

# nginx example: listen on 80 and proxy to 8080
server {
    listen 80;
    server_name _;
    location / { proxy_pass http://127.0.0.1:8080; }
}

Run nginx/Apache (they handle low ports safely) and proxy traffic to your app on 8080.

Quick troubleshooting and safety notes

  • Check macOS firewall settings in System Preferences > Security & Privacy > Firewall; app-level blocking can interfere.
  • Inspect pf rules with sudo pfctl -sr and check logs if connections are dropped.
  • Avoid running app as root long-term; bind first, then drop privileges (setuid) or use a proxy.
  • Behavior and tools (launchctl, pf) evolved across macOS releases — verify commands on your OS if something fails.

Most likely you weren't running the program as a privileged user. Mac OS X requires administrative privileges to bind on ports < 1024.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.