Jump to content

Hosting two websites on two separate PCs in same network.

Go to solution Solved by mariushm,

It would be a bit tough to do it.  Maybe if you implement some load balancing / reverse proxy solution on one of the servers.

 

Normally you'd set the A record for your website 1 to your external IP, and then set port forwarding in your router on port 80 (http) and 443 (ssl) to the internal ip of the server (ex 192.168.1.11)

You can set the second website's A record to same IP,  but your router will forward anything coming on port 80 or 443 to the first server, not the second.. so your option would be either to set up a sort of reverse proxy / load balancer on first server to redirect any traffic for website 2 to server 2 , or to simply set up website 2 on first server as a separate vhost (easy to do in apache or nginx or whatever) - if needed, you could run a database server or some application / api on second server and have your website(s) hosted on first server access resources of second server. 

Hello!

 

My setups is following:

 

Router: Google Nest Router

- then -

Switch: Unmanaget switch

- then - 

Server 1 (physical): 192.168.1.11 running webpage1

Server 2 (physical): 192.168.1.12 running webpage2

 

Is it possible to make it so when I type www.website1.com in web browser, router points to Server 1 and when I type www.website2.com router points to Server 2?

 

Thank you.

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Dj Bacon said:

Hello!

 

My setups is following:

 

Router: Google Nest Router

- then -

Switch: Unmanaget switch

- then - 

Server 1 (physical): 192.168.1.11 running webpage1

Server 2 (physical): 192.168.1.12 running webpage2

 

Is it possible to make it so when I type www.website1.com in web browser, router points to Server 1 and when I type www.website2.com router points to Server 2?

 

Thank you.

 

Yes it is. You could run a DNS service on one or both of the servers and have your routers DHCP point to those DNS servers. Then if you get a DNS request for www.website2.com the DNS server will know the IP address as 192.168.1.11 and return that website.

 

An other option, though static, is to edit the hosts file on each pc in your network.

https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Naijin said:

Yes it is. You could run a DNS service on one or both of the servers and have your routers DHCP point to those DNS servers. Then if you get a DNS request for www.website2.com the DNS server will know the IP address as 192.168.1.11 and return that website.

Thank you, but that probably will not work if I'm trying to access those websites from outside my local nwtwork.

Link to comment
Share on other sites

Link to post
Share on other sites

It would be a bit tough to do it.  Maybe if you implement some load balancing / reverse proxy solution on one of the servers.

 

Normally you'd set the A record for your website 1 to your external IP, and then set port forwarding in your router on port 80 (http) and 443 (ssl) to the internal ip of the server (ex 192.168.1.11)

You can set the second website's A record to same IP,  but your router will forward anything coming on port 80 or 443 to the first server, not the second.. so your option would be either to set up a sort of reverse proxy / load balancer on first server to redirect any traffic for website 2 to server 2 , or to simply set up website 2 on first server as a separate vhost (easy to do in apache or nginx or whatever) - if needed, you could run a database server or some application / api on second server and have your website(s) hosted on first server access resources of second server. 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Dj Bacon said:

Thank you, but that probably will not work if I'm trying to access those websites from outside my local nwtwork.

No this will not work if you are outside your network. If you want your websites to be available outside your network you could always use a dynamic DNS service and port forwarding on your router. For example noip.org. You could advertise your website as dj_bacon1.noip.org and it would be forwarded to 192.168.1.11 and dj_bacon2.noip.org to forward to 192.168.1.12.

 

That way you don't have to run your own DNS service inside your network but just a service to automatically update your public IP. You have to make sure the correct ports are forwarded on your modem/router and if it's public, put the correct security measures in place. I.e. 2FA, disable admin account and use dedicated logins and strong passwords if you're going to open SSH/telnet for example.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, mariushm said:

It would be a bit tough to do it.  Maybe if you implement some load balancing solution on one of the servers.

 

Normally you'd set the A record for your website 1 to your external IP, and then set port forwarding in your router on port 80 (http) and 443 (ssl) to the internal ip of the server (ex 192.168.1.11)

You can set the second website's A record to same IP,  but your router will forward anything coming on port 80 or 443 to the first server, not the second.. so your option would be either to set up a sort of reverse proxy / load balancer on first server to redirect any traffic for website 2 to server 2 , or to simply set up website 2 on first server as a separate vhost (easy to do in apache or nginx or whatever) - if needed, you could run a database server or some application / api on second server and have your website(s) hosted on first server access resources of second server. 

Reverse proxy / load balancer sounds promising. Thank you.

If It will be too difficult to implement I will move them both to single server.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Naijin said:

No this will not work if you are outside your network. If you want your websites to be available outside your network you could always use a dynamic DNS service and port forwarding on your router. For example noip.org. You could advertise your website as dj_bacon1.noip.org and it would be forwarded to 192.168.1.11 and dj_bacon2.noip.org to forward to 192.168.1.12.

Unfortunately that will also not work (I think), because dynamic dns will recirect to single external IP and router will point to only one server on port 80.

I think the suggestion about reverse proxy / load balancer might be the solution here.

Link to comment
Share on other sites

Link to post
Share on other sites

Just use port based virtual servers.

 

Have webserver 1 running on machine 1 listening on port 80 and your firewall forwarding port 80 to machine 1.

Have webserver 2 running on machine 2 listening on port 81 and your firewall forwarding port 81 to machine 2.

For SSL use 443 on server 1 and 444 on server 2.

 

That should be all you need to do.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Master Disaster said:

Just use port based virtual servers.

 

Have webserver 1 running on machine 1 listening on port 80 and your firewall forwarding port 80 to machine 1.

Have webserver 2 running on machine 2 listening on port 81 and your firewall forwarding port 81 to machine 2.

For SSL use 440 on server 1 and 441 on server 2.

 

That should be all you need to do.

That will work, but then I have to type www.website1.com for first one and www.website2.com:81 for second one and that's not an option. Both websites need to be accessible using domain name without specifying port.

Link to comment
Share on other sites

Link to post
Share on other sites

You have to use a reverse proxy, easiest solution. Have both website1.com and website2.com point to your ip, your router forwards 80/443 to one machine, the webserver on that machine either serves website1.com if that's what was requested or reverse proxies to the other machine if website2.com was requested.

 

nginx can do that pretty easily.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Dj Bacon said:

That will work, but then I have to type www.sebsite1.com for first one and www.website2.com:81 for seconds one and that's not and option. Both website need to be accessible using domain name without specifying port.

IIRC you can solve this by running your own DNS server and using 1 master A record and 2 AAA records, one for each domain since A records use an IP while AAA records use FQDN allowing you to filter traffic from the DNS.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Kilrah said:

You have to use a reverse proxy, easiest solution. Have both website1.com and website2.com point to your ip, your router forwards 80/443 to one machine, the webserver on that machine either serves website1.com if that's what was requested or reverse proxies to the other machine if website2.com was requested.

 

nginx can do that pretty easily.

Yes, I just searched for reverse proxy on Apache and it looks pretty easy to implement.

Thank you.

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Master Disaster said:

IIRC you can solve this by running your own DNS server and using 1 master A record and 2 AAA records, one for each domain since A records use an IP while AAA records use FQDN allowing you to filter traffic from the DNS.

Unfortunately that only works for local network. 

Both websites needs to be accessible from outsite.

 

As suggested reverse proxy seems to be the solution.

Link to comment
Share on other sites

Link to post
Share on other sites

"When there's a will, there's a way" Hahaha i had to quote that because just like this thread, everyone I asked said this was not possible. But here I am now, sharing what I've learned!

The answer to your problem: Application Request Routing on IIS. This is *supposed* to be used as a load balancer to spread the load of a single application amongst servers. When used with URL Rewrite we can use this to turn IIS into a forward proxy to forward your HTTP/S requests to a server downstream.

 

Unfortunately, that's the help I can offer right now as I don't have access to my servers, thus can't see what I've done. I remember following the guide below but with some tweaks. Hope I was able to provide you with a lead.

 

Creating a Forward Proxy Using Application Request Routing | Microsoft Docs

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Why are you doing this on two server?

Apache or nginx can host many websites with their own ssl certs all on the same. If you do need two (say one is an application server?), then yes you can setup a reverse proxy on either apache or nginx.

"Only proprietary software vendors want proprietary software." - Dexter's Law

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×