Skip to content

Instantly share code, notes, and snippets.

@allexradu
Forked from novemberborn/setup.md
Last active March 28, 2024 20:02
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allexradu/52f88344f207960621d5f086fcaf4b69 to your computer and use it in GitHub Desktop.
Save allexradu/52f88344f207960621d5f086fcaf4b69 to your computer and use it in GitHub Desktop.
OS X Setup virtual hosts on two different ports

Changes with .dev domains in mind.

Step 1 : Assign at least two IP address to your MAC OS (one per domain), let's say :

192.168.0.51
192.168.0.52

To setup the second IP you will have to add a second Ethernet Adapter (logical not physical).

Step 2 : As you don't have a DNS server, you could setup your /etc/hosts file, by adding :

192.168.0.51     dev.hostone.com
192.168.0.52     dev.hosttwo.com

Step 3 : Assign aliases to your loopback interface :

sudo ifconfig lo0 192.168.0.51 alias
sudo ifconfig lo0 192.168.0.52 alias

Create /etc/pf.anchors/dev, containing:

rdr pass inet proto tcp from any to 192.168.0.51 port 80 -> 127.0.0.1 port 8000
rdr pass inet proto tcp from any to 192.168.0.52 port 80 -> 127.0.0.1 port 3000

Edit /etc/pf.conf. After rdr-anchor "com.apple/*" insert rdr-anchor "dev" (on its own line). After load anchor "com.apple" from "/etc/pf.anchors/com.apple" insert load anchor "dev" from "/etc/pf.anchors/dev" (again on its own line). It'll look something like this:

scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "dev"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "dev" from "/etc/pf.anchors/dev"

Test the config:

sudo pfctl -v -n -f /etc/pf.conf

Then reload:

sudo pfctl -ef /etc/pf.conf
@yudijohn
Copy link

how to use HTTPS? like https://dev.hostone.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment