Virtual hosts is very useful for heavy-loaded sites to access specific directory each domain, Each domain that is configured will direct the visitor to a specific directory holding that site's information, never indicating that the same server is also responsible for other sites.
You can get Apache installed on your server through apt-get:
1. Create the Directory Structure
Within each of these directories, we will create a public_html folder that will hold our actual files. This gives us some flexibility in our hosting.
and test.html file under public folder and add content to test.html
2. We should also modify our permission to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly:
3. my configuration will make a virtual host for demo.com
Then Create your <virtual-host>.conf file in the following way:
Enable the website
Restart the server
Then edit your /etc/hosts file in this way:
and Test your result
Restart the server
You can get Apache installed on your server through apt-get:
sudo apt-get update sudo apt-get install apache2
Within each of these directories, we will create a public_html folder that will hold our actual files. This gives us some flexibility in our hosting.
sudo mkdir /var/www/demo.com/public
2. We should also modify our permission to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly:
sudo chmod -R 755 /var/www/
Then Create your <virtual-host>.conf file in the following way:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/demo.conf
Edit the file .conf
sudo nano /etc/apache2/sites-available/demo.conf
add this to demo.conf
<VirtualHost *:80> ServerName demo.local ServerAlias www.demo.local ServerAdmin admin@demo.local DocumentRoot /var/www/demo.com/public <Directory /var/www/demo.com/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
sudo a2ensite demo.conf
sudo service apache2 restart
127.0.0.1 localhost demo.local www.demo.local
http://demo.local
No comments:
Post a Comment