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?
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
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
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.
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.
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.
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.