![]() | Red Hat Certified System Administration 8 |
Exercise 03: Configuring Apache Virtual HostsIn this exercise, you create two virtual hosts. To set up virtual hosts, you first set up name resolution, after which you create the virtual hosts’ configuration. Because SELinux has not been discussed yet, you temporarily switch off SELinux. NoteI later tell you that you should never switch off SELinux. For once, I make an exception to this important security rule. To focus on what needs to be done on the Apache web server, it is easier to focus just on Apache and not to configure SELinux as well. 1. On both server1 and server2, open the file /etc/hosts with an editor and add two lines that make it possible to resolve the names of the virtual host you are going to create to the IP address of the virtual machine: Click here to view code image 192.168.4.210 server1.example.com server1192.168.4.220 server2.example.com server2 192.168.4.210 account.example.com account 192.168.4.210 sales.example.com sales 2. On server1, open a root shell and add the following to the /etc/httpd/conf/httpd.conf file. (You can leave all other settings as they are.) Click here to view code image Require all granted AllowOverride None 3. On server1, open a root shell and create a configuration file with the name account.example.com.conf in the directory /etc/httpd/conf.d. Give this file the following content: Click here to view code image ServerAdmin webmaster@account.example.com DocumentRoot /www/docs/account.example.com ServerName account.example.com ErrorLog logs/account.example.com-error_log CustomLog logs/account.example.com-access_log common 4. Close the configuration file, and from the root shell type mkdir -p /www/docs/account.example.com. 5. Create a file with the name index.html in the account document root, and make sure its contents read “Welcome to account.” 6. Temporarily switch off SELinux using setenforce 0. 7. Use systemctl restart httpd to restart the Apache web server. 8. Use curl http://account.example.com. You should now see the account welcome page. (You may have to install elinks, using yum install -y curl.) 9. Back on the root shell, copy the /etc/httpd/conf.d/account.example.com.conf file to a file with the name /etc/httpd/conf.d/sales.example.com.conf. 10. Open the sales.example.com.conf file in vi, and use the vi command :%s/account/sales/g. This should replace all instances of “account” with the “sales.” 11. Create the /www/docs/sales.example.com document root, and create a file index.html in it, containing the text “Welcome to the sales server.” 12. Restart httpd and verify that both the account and the sales servers are accessible. |