Apache utilizes Virtual Host technology, allowing multiple websites to run on a single server. Each website shares the server's IP address, with client requests directing the server to the corresponding site. Virtual Host technology significantly reduces the workload for server administrators. Provided there are sufficient CPU, memory, and disk resources, there is no limit to the number of websites that can be deployed on the server.
In the FreeBSD 12 operating system, the directory for storing websites on an Apache server is: /usr/local/www/apache24/data/. It is necessary to create a separate directory for each website. For example, consider three websites: example.com, example.net, and example.org.
$ sudo mkdir -p /usr/local/www/apache24/data/example.com/public_html
$ sudo mkdir -p /usr/local/www/apache24/data/example.net/public_html
$ sudo mkdir -p /usr/local/www/apache24/data/example.org/public_html
Change the permissions of the above directories to 755 to allow everyone to read and execute them.
$ sudo chmod -R 755 /usr/local/www/apache24/data/example.com/public_html
$ sudo chmod -R 755 /usr/local/www/apache24/data/example.net/public_html
$ sudo chmod -R 755 /usr/local/www/apache24/data/example.org/public_html
Ensure that files in the above directories inherit the owner from the root directory.
$ sudo find /usr/local/www/apache24/data/example.com/public_html -type d -exec chmod g+s {} \;
$ sudo find /usr/local/www/apache24/data/example.net/public_html -type d -exec chmod g+s {} \;
$ sudo find /usr/local/www/apache24/data/example.org/public_html -type d -exec chmod g+s {} \;
In the FreeBSD 12 operating system, the default configuration file for Apache is: /usr/local/etc/apache24/httpd.conf. Additionally, the web server scans the directory: /usr/local/etc/apache24/Includes. Files in this directory are also merged into the configuration file.
Create a separate configuration file for each website. For example, take example.com.
$ sudo nano /usr/local/etc/apache24/Includes/example.com.conf
The content of the configuration file is as follows.
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot /usr/local/www/apache24/data/example.com/public_html
ErrorLog "/var/log/example.com.log"
CustomLog "/var/log/example.com.log" common
</VirtualHost>
Restart Apache to apply the changes.
$ sudo service apache24 restart
Next, add a default homepage for each website to begin serving them to visitors. For the example.com website, create an index.html file in the root directory.
$ sudo nano /usr/local/www/apache24/data/example.com/public_html/index.html
The content of the file is as follows:
<html>
<head>
<title>The example.com website</title>
</head>
<body>
<h1>Welcome to <b>example.com</b> website.</h1>
<p>This content confirms that the <b>example.com</b> website is working correctly.</p>
</body>
</html>
Finally, visit: http://example.com to test if it displays correctly. The procedure for other websites is similar. This concludes the method of running multiple websites on a FreeBSD cloud server using Apache.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58