where is apache virtual host file code example
Example 1: virtual host apache
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
ServerAdmin [email protected]
DirectoryIndex index.html
DocumentRoot /home/demo/public_html/domain1.com/public
LogLevel warn
ErrorLog /var/log/apache2/error-mydomainname.com.log
CustomLog /var/log/apache2/access-mydomainname.com.log combined
</VirtualHost>
sudo a2ensite domain1.com
sudo /etc/init.d/apache2 reload
Example 2: apache virtual host
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
ServerAdmin [email protected]
DirectoryIndex index.html
DocumentRoot /home/demo/public_html/domain1.com/public
LogLevel warn
ErrorLog /var/log/apache2/error-mydomainname.com.log
CustomLog /var/log/apache2/access-mydomainname.com.log combined
</VirtualHost>
sudo a2ensite domain1.com
sudo /etc/init.d/apache2 reload
Example 3: create a virtual host in apache
STEP 1:
<VirtualHost *:80>
ServerAdmin admin@DOMAIN_URL
ServerName DOMAIN_URL
ServerAlias DOMAIN_URL
DirectoryIndex index.html index.php
DocumentRoot /var/www/DOMAIN_URL/public_html/public/
<Directory /var/www/DOMAIN_URL/public_html/public/>
Options Indexes FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog /var/www/DOMAIN_URL/log/error.log
CustomLog /var/www/DOMAIN_URL/log/access.log combined
</VirtualHost>
STEP 2: With our virtual host files created, we must enable them. We’ll be
using the a2ensite tool to achieve this goal.
sudo a2ensite example.com.conf
STEP 3: When you are finished, you need to restart Apache to make these changes
take effect and use systemctl status to verify the success of the restart.
sudo systemctl restart apache2
refrence:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart