Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This lets you run nginx as a normal user and still receive connections on port 80 and 443. Setup nginx to listen to port 8080 for http and 8443 for https.
This is not actually necessary, as you can use the following commands to allow nginx to bind to privileged ports:
$ sudo chown root:wheel /usr/local/opt/nginx/bin/nginx
$ sudo chmod u+s /usr/local/opt/nginx/bin/nginx
Forward port 80 to port 8080 and 443 to 8443 so that you can run nginx as a normal user.
Save to: /Library/LaunchDaemons/nginx.firewall.plist
sudo curl -L -o /Library/LaunchDaemons/nginx.firewall.plist
sudo launchctl load -Fw /Library/LaunchDaemons/nginx.firewall.plist
sudo launchctl unload /Library/LaunchDaemons/nginx.firewall.plist
sudo rm /Library/LaunchDaemons/nginx.firewall.plist
sudo pfctl -a "" -F all
sudo pfctl -a "" -F all
Inspired by firewall:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
sysctl -w net.inet.ip.forwarding=1;
echo "rdr pass proto tcp from any to any port {80,8080} -> port 8080" | pfctl -a "" -Ef -
echo "rdr pass proto tcp from any to any port {443,8443} -> port 8443" | pfctl -a "" -Ef -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment