Virtual hosting in Red Hat (or any Linux-based system) refers to hosting multiple websites or domains on a single server. This can be achieved using Apache HTTP Server (commonly known as Apache) or NGINX. Below is a guide to set up virtual hosting in Apache on a Red Hat-based system like RHEL.
Ensure Apache is installed on your RHEL system. If not, install it using:
Enable and start the Apache service to ensure it runs at startup.
Apache uses virtual host configuration files to manage multiple sites.
Example Configuration for Two Sites:
- Create directories for the websites:
- Set permissions:
- Add test content:
Site1
Site2
- Create virtual host configuration files: Virtual host files are stored in /etc/httpd/conf.d/.
Virtual Host : Create a file named vhost.conf
Add the following configuration:
To test locally without DNS setup, update the /etc/hosts file:
Add entries for your test domains:
After making these changes, restart Apache to apply the configurations:
Open a web browser and navigate to:
- http://site1.local.com → Should display "Welcome to Site 1."
- http://site2.local.com → Should display "Welcome to Site 2."
- Check Apache Syntax: Before restarting Apache, check for configuration errors:
-
Check Logs: If there are issues, check the Apache logs for errors:
sudo tail -f /var/log/httpd/error_log
-
Firewall Configuration: Ensure the firewall allows HTTP traffic:
This setup enables you to host multiple websites on a single Red Hat server using Apache.