Changes between Version 3 and Version 4 of Csle2022/Agenda/databaseandweb


Ignore:
Timestamp:
Oct 20, 2022, 9:59:49 AM (2 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Csle2022/Agenda/databaseandweb

    v3 v4  
    8787= Apache Virtual Hosting =
    8888
     89Using virtual hosts, one Apache instance can serve multiple websites. Each domain or individual site that is configured using Apache will direct the visitor to a specific directory holding that site’s information. This is done without indicating to the visitor that the same server is also responsible for other sites.
     90
     91Note: Before creating a virtual host for a web site domain, the particular domain or subdomain should be created. For this please contact your domain manager of your institutional IT department or relevant domain company. Then this domain should be assigned a DNS entry (A or AAAA record) to work on a web browser. In our case DNS entry should be pointed to your server IP.
     92
     93Presuming you meet the prerequisites below will be the steps to create virtual hosts.
     94
     95First you need to create a appropriate directory structure for each website hosted under each domain. By default root web directory in a Ubuntu system will be /var/www/html. For our setup we will use below directory structure for each site.
     96
     97web site for domain 1 - /var/www/your_domain_1/public_html
     98web site for domain 2 - /var/www/your_domain_2/public_html
     99web site for domain 3 - /var/www/your_domain_3/public_html
     100
     101In our example we hope to create three subdomains called web,sales and lms. So the full domain names will be web.your_domain.com, sales.your_domain.com and lms.your_domain.com respectively.
     102Use these commands, with your own domain names, to create your directories:
     103
     104{{{
     105sudo mkdir -p /var/www/web.your_domain/public_html
     106sudo mkdir -p /var/www/sales.your_domain/public_html
     107sudo mkdir -p /var/www/lms.your_domain/public_html
     108}}}
     109
     110We are going to install moodle under lms subdomain. For other two domains we will create dummy web pages for each.
     111
     112{{{
     113sudo nano /var/www/web.your_domain/public_html/index.html
     114}}}
     115
     116{{{
     117<!DOCTYPE html>
     118<html lang="en" dir="ltr">
     119  <head>
     120    <meta charset="utf-8">
     121    <title>Welcome to WEB</title>
     122  </head>
     123  <body>
     124    <h1>Success! WEB home page!</h1>
     125  </body>
     126</html>
     127}}}
     128
     129Also create a similar page for the sales sub-domain.
     130
     131Once created with a sample web site we have to change ownership of the directories to the web server user.
     132
     133{{{
     134sudo chown -R www-data: /var/www/*
     135}}}
     136
     137Now we are done with creating web sites and directories. Now we need to do the actual apache server configurations for the virtual hosting.
     138
     139On Ubuntu systems, Apache Virtual Hosts configuration files are located in /etc/apache2/sites-available directory. They can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory, which Apache read during the startup. Here we need to create a seperate configuration file for each domain/sub-domain as below.
     140
     141{{{
     142sudo nano /etc/apache2/sites-available/web.your_domain.com.conf
     143}}}
     144
     145And add the below configurations,
     146
     147{{{
     148<VirtualHost *:80>
     149    ServerName web.dhammikalalantha.com
     150    ServerAlias web.dhammikalalantha.com
     151    ServerAdmin webmaster@dhammikalalantha.com
     152    DocumentRoot /var/www/web.dhammikalalantha.com/public_html
     153
     154    <Directory /var/www/web.dhammikalalantha.com/public_html>
     155        Options -Indexes +FollowSymLinks
     156        AllowOverride All
     157    </Directory>
     158
     159    ErrorLog ${APACHE_LOG_DIR}/web.dhammikalalantha.com-error.log
     160    CustomLog ${APACHE_LOG_DIR}/web.dhammikalalantha.com-access.log combined
     161</VirtualHost>
     162}}}
     163
     164Similarly do the necessary configurations for the domain sales.
     165
     166{{{
     167sudo nano /etc/apache2/sites-available/sales.your_domain.com.conf
     168}}}
     169
     170{{{
     171<VirtualHost *:80>
     172    ServerName sales.dhammikalalantha.com
     173    ServerAlias sales.dhammikalalantha.com
     174    ServerAdmin webmaster@sales.dhammikalalantha.com
     175    DocumentRoot /var/www/sales.dhammikalalantha.com/public_html
     176
     177    <Directory /var/www/sales.dhammikalalantha.com/public_html>
     178        Options -Indexes +FollowSymLinks
     179        AllowOverride All
     180    </Directory>
     181
     182    ErrorLog ${APACHE_LOG_DIR}/sales.dhammikalalantha.com-error.log
     183    CustomLog ${APACHE_LOG_DIR}/sales.dhammikalalantha.com-access.log combined
     184</VirtualHost>
     185}}}
     186
     187Once we do the configurations we have to enable the created sites as below,
     188
     189{{{
     190sudo a2ensite web.dhammikalalantha.com
     191sudo a2ensite sales.dhammikalalantha.com
     192}}}
     193
     194Once done, test the configuration for any syntax errors with.
     195{{{
     196sudo apachectl configtest
     197}}}
     198
     199Restart the Apache service for the changes to take effect.
     200{{{
     201sudo systemctl restart apache2
     202}}}
     203
     204Now that you have your virtual hosts configured, you can test your setup by going to the domains that you configured in your web browser. Below will be the output for the sites we created.
     205
     206[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web4.png)]]
     207
     208Also check the other site created.