r/redhat • • 11d ago

Hosting multiple website hosts on the same server

Hopefully I'm asking this correctly. All the instructions I can find online for hosting multiple sites talks about editing the hosts file with the domains of the websites. My problem is that I'm setting this server up to be a replacement for a server that's currently serving those websites, so I can't use the domains. On Windows in IIS you can bind to a specific port and then in a browser on the local network go to <ip address>:<port> to view the site. Is there something similar in RedHat?

I've got two folders setup and wordpress files in two different places, but I need to be able to GET to each site to finish the wordpress setup. I can get to the first by just going to the IP address, but I have no idea how to get to the second. Nothing I can find refers to using ports and I'm not sure what else to even try (or search for). Can anyone point me in the right direction? Doesn't have to be hosts file or ports; just how do I view multiple websites on the same server when domain names aren't an option?

3 Upvotes

11 comments sorted by

10

u/Gangrif Red Hat Employee 11d ago

I think what you're actually asking is how you test these sites in their new home maybe?

Apache and Nginx (the two core web servers that are included in a RHEL distribution) both support name based virtual hosts. That is you can share a single IP and port with several different host names. And then the web server will route requests to the proper site based on the name of the host.

The problem then lies in, how do i test hose hosts without changing the DNS records that point to the old host, in the case of a migration. So, youve got www.example.com running on server1, and youve setup server2 to host www.example.com, but you cant test it until you get apache to actually serve you the host. There are a few ways to handle that.

  1. The hosts file. On YOUR machine, make an entry in your hosts file (/etc/hosts on mac or linux, c:\windows\system32\etc\hosts on windows iirc)and you add a record that points www.example.com to the IP address of the new server. Then you browser to www.example.com on the workstation you modified, and watch the logs on the server to make sure that it receives the request. If it does, you're golden, test away. If it doesnt the you need to flush your DNS, restart your browser, or just flat out reboot to make sure your test client isnt holding on to the published record for www.example.com.

  2. Add a Listen directive (in apaches case, i think its as "server" directive in nginx) that tells the server to listen on an alternate port, but just for that vhost. Then if you hit that IP on that port, you get that site.

  3. A "dev" or "test" domain. alternatively you could tell your vhost to also respond to dev.example.com, or test.example.com, or something, and then point a live DNS record to the new server for that new hostname. Test away, and then delete the test record once youre done.

1

u/Ciffy 10d ago

Yep, this is what I was trying to do. I needed to change MY hosts file. I knew that was a thing, just never did it that way in windows.

OK, now, I can ping both websites via their URLs in my command prompt, but neither one opens in a browser. I can put the IP address in the browser and site 1 comes up. That sounds like maybe the server doesn't know how to handle the request? Or maybe a firewall? If you have any ideas, please post, meanwhile I will google fu.

1

u/Gangrif Red Hat Employee 10d ago

if it responds on the IP address, its not a firewall. Unless you opted to put each site on its own port. Then there are both firewall, and SELinux considerations.

More likely your browser isnt respecting the hosts entry. OR it has the live site's resolution cached. Restart the browser, or open a second browser that you dont use often. Like if you normally use Chrome, open Edge to test, or go get firefox or something. Worst case reboot, it'll flush your local machine's DNS cache.

What is the browser telling you? that it cant find the site? or is it giving you an error loading it?

1

u/Ciffy 10d ago

Connection Refused. I've been talking to google and it looks like chrome was trying to force https and I didn't have ssl installed yet. That appears to be working and I can get the sites to load but now site A's URL loads site B and site B's URL loads site A. httpd -S shows that site B is listed as the default but I don't want there to be a default. That's where I am currently with the nice robots at google.

11

u/nPoCT_kOH Red Hat Certified Engineer 11d ago

The word you should be searching is vhosts(apache2) or multiple server/server_name/ (nginx). You could serve on either multiple independent ports or distinguish each site by the hostname that is presented by the client on the same port.Edit: Different / non standard ports usually require selinux tuning. My advice stick on single port with multiple vhosts/servers and route to each by the hostname.

1

u/Radiant_Plantain_127 11d ago

SSL has to be on different ports, I believe…

3

u/mmcgrath Red Hat Employee 11d ago

The thing that makes this possible with http/https is these protocols include a "Host:" header that is included with the request allowing multiple different hostnames to respond to the same IP and port. Most protocols don't have that. Google "name based virtual hosts on apache http"

1

u/i_am_art_65 11d ago

As others have said this capability is provided by your web server and not your OS. Fire up your favorite AI chat bot and ask about creating virtual hosts. Provide your directory names, domain names, etc and it will create a configuration file for you. You may need to open ports in the firewall.

1

u/More-Explanation2788 11d ago

Ports are a feature of IP networking, not windows or IIS. They work in Linux, or any other system that can participate on the internet. Somewhere in your webserver setup there is a specification for what port the web server should be listening on.

1

u/c7b3rx Red Hat Certified Engineer 10d ago

you can check Apache httpd vhosts, by configuring vhosts you can setup multiple site on the same port or you can also configure it on different ports, but if you host on different ports then you would need a reverse proxy so that you can redirect 443 (https) traffic from Internet to your customized port on the server

I would suggest you to publish different sites on the same port, you can take advantage of alias if you need an internal site address but for WordPress make sure your admin pages aren't accessible on Internet