For some projects I wanted to serve the development environment on my local port

  1. This wasn’t straightforward with macOS until I found this workaround. Forward the virtual environment’s ports 80 and 443 to 8080 and 8443 respectively. Then forward 8080 and 8443 back to 80 and 443 using local firewall rules.
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443

After macOS 10.10

With the release of macOS 10.10 (Yosemite), ipfw has been removed from the operating system. [This post](http://salferrarello.com/mac-pfctl-port- forwarding/) explains a workaround. By adding a few rules to /etc/pf.conf the same result is accomplished.

Set the necessary rules.

echo "
rdr pass on lo0 inet proto tcp from any to self port 80 -> 127.0.0.1 port 8080
rdr pass on en0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass on en1 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
" | sudo pfctl -ef -

Clear the current rules.

sudo pfctl -F all -f /etc/pf.conf

Display the current rules.

sudo pfctl -s nat