Having two subdomains on one public IP addres behind pFsense router
This can be done with the squid3 package. squid3 includes a Reverse Proxy server
Install the squid3 package...
- System > Packages
- Scroll down to squid3 and press the + button
After installation go to Services > Reverse Proxy
Under the General tab...
- Reverse Proxy interface: WAN
- external FQDN: YourFQDN.com (this should be your main name, but it doesn't mean you're limited to subdomains of the name you put there)
- Enable HTTP reverse mode checked
Under the Web Servers tab, add the (internal) IP of each of your servers
- Press the + button
- Enable this peer checked
- Peer Alias: make up a nickname for your server
- Peer IP: the IP address of your server
- Peer Port the port for your server (probably 80)
- Save
Under the Mappings tab, add the domain name for each of your servers
- Enable this URI checked
- Group name: make up a nickname
- Peers: select the corresponding server you setup in the Web Servers tab
- Save
Finally, under Firewall > Rule, create rule to direct traffic to the reverse proxy server
- Press the + button to add a rule
- The default settings...
- Pass, WAN, TCP, Source Type any
- Destination: WAN address
- Destination port range: HTTP
- Save
This rule should be LAST if you have other rules configured forwarding from the outside in.
Any names you use must be registered to point to your external IP-- so if your domain name is example.com, in order to create subdomains in pfsense you will need to setup a record with your domain registrar point *.example.com.
I learned from this helpful tutorial: http://sdrv.ms/V8qLfK
You can't do this with NAT because NAT only cares about IP Addresses and Ports (Layer 3 + 4). The HTTP Host
header is above that so NAT implementations are never aware of it.
To achieve what you are looking for, you need a Reverse Proxy. (Apache, Squid, nginx, lighttpd etc). A reverse proxy is capable of examining the Host
header in the HTTP request and forwarding the traffic to the appropriate server.
This is possible! I've successfully done something very similar using squid reverse proxy. There are guides on setting it up, but it is pretty easy. Start by installing it via the pfsense package manager, then configure some servers and mappings.
How this works:
It basically starts a web server on port 80, or 443 if you use the https option. You can then define subdomains, like "web.mydomain.com" and "portal.mydomain.com", etc, and configure where they forward to on the internal network.
Then, it will parse the request url and pass it to the appropriate server. I am taking this one step further and running two https based services on one server, using different ports. service1.mydomain.com will connect to https:// server :8443, while service2.mydomain.com will connect to https:// server :8444
FYI, My subdomains on the domain registrar's dns all point to the same "external facing" WAN IP on the pfsense box.
Does this help?