| 161 | = Registering your Domain Names and DNS configuration for your Domains = |
| 162 | |
| 163 | As you know we can't use any preferred domain for our services, websites as we wanted to do. First we have to register them in a relevant domain registry where usually we have to pay. In case you want a ac.lk sub domain you have to get it through LEARN. Once you get your domains registered they are to be assigned IP addresses so that they can be used in your services for hosting services, websites etc. Assigning of IP addresses to the domain names is done through DNS lookup service. This DNS service is also can be accomplished through the relevant domain registry or web hosting service. For the ac.lk domain, LEARN or your institutional network/system administrator will do that for you. |
| 164 | |
| 165 | Receiving domains costs or need the approval from the System Administrator. Hence, for this workshop we can use hosts file in your computer operating system to create any arbitrary domain for your self. Hosts file will override any public DNS but only for your own computer. |
| 166 | |
| 167 | == Add domains to the hosts file in Windows == |
| 168 | |
| 169 | To add domains to the hosts file in Windows please Run the Notepad as the Adminitrator as below. |
| 170 | |
| 171 | [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web29.png)]] |
| 172 | |
| 173 | Then go to /Windows/System32/drivers/etc directory. If you cannot view hosts file please select All Files from the drop down list at bottom. Now open hosts file. |
| 174 | |
| 175 | [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web30.png)]] |
| 176 | |
| 177 | Now as below edit the hosts file and add you domains with the IP address of your guest VM. |
| 178 | |
| 179 | [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web31.png)]] |
| 180 | |
| 181 | == Add domains to the hosts file in Linux == |
| 182 | |
| 183 | To add domains to the hosts file edit the hosts file as below. Once done save it. |
| 184 | |
| 185 | {{{ |
| 186 | nano /etc/hosts |
| 187 | |
| 188 | |
| 189 | 127.0.0.1 localhost |
| 190 | 127.0.1.1 web |
| 191 | 10.1.1.240 web.your_domain.com |
| 192 | 10.1.1.240 wp.your_domain.com |
| 193 | 10.1.1.240 lms.your_domain.com |
| 194 | 10.1.1.240 xy.your_2nd_domain.com |
| 195 | }}} |
| 196 | |
| 197 | Now you should be able to access the virtual hosts by their domain names within the computer. |
| 198 | |
| 199 | To check it you can ping to the domain or browse from the web browser. |
| 200 | |
| 201 | {{{ |
| 202 | ping wp.your_domain.com |
| 203 | ping xy.your_2nd_domain.com |
| 204 | }}} |
| 205 | |
| 206 | |
| 261 | openssl req -x509 -newkey rsa:4096 -keyout /etc/ssl/private/ssl-lms.key -out /etc/ssl/certs/ssl-lms.crt -nodes -days 1095 |
| 262 | |
| 263 | |
| 264 | You are about to be asked to enter information that will be incorporated |
| 265 | into your certificate request. |
| 266 | What you are about to enter is what is called a Distinguished Name or a DN. |
| 267 | There are quite a few fields but you can leave some blank |
| 268 | For some fields there will be a default value, |
| 269 | If you enter '.', the field will be left blank. |
| 270 | ----- |
| 271 | Country Name (2 letter code) [AU]:LK |
| 272 | State or Province Name (full name) [Some-State]:Central Province |
| 273 | Locality Name (eg, city) []:Peradeniya |
| 274 | Organization Name (eg, company) [Internet Widgits Pty Ltd]:LEARN |
| 275 | Organizational Unit Name (eg, section) []:IT Division |
| 276 | Common Name (e.g. server FQDN or YOUR name) []:lms.dhammikalalantha.com |
| 277 | Email Address []:lalantha@learn.ac.lk |
| 278 | |
| 279 | sudo a2enmod ssl |
| 280 | |
| 281 | sudo systemctl restart apache2 |
| 282 | |
| 283 | nano lms-ssl.conf |
| 284 | |
| 285 | <IfModule mod_ssl.c> |
| 286 | <VirtualHost *:443> |
| 287 | |
| 288 | ServerName lms.dhammikalalantha.com |
| 289 | ServerAdmin you@yourwebsite.com |
| 290 | DocumentRoot /var/www/lms.dhammikalalantha.com/public_html |
| 291 | |
| 292 | ErrorLog ${APACHE_LOG_DIR}/lms-error.log |
| 293 | CustomLog ${APACHE_LOG_DIR}/lms-access.log combined |
| 294 | |
| 295 | |
| 296 | SSLCertificateFile /etc/ssl/certs/ssl-lms.crt |
| 297 | SSLCertificateKeyFile /etc/ssl/private/ssl-lms.key |
| 298 | |
| 299 | RewriteEngine on |
| 300 | RewriteCond %{SERVER_NAME} =lms.dhammikalalantha.com |
| 301 | RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # port 80 -- > 443 redirection |
| 302 | </VirtualHost> |
| 303 | </IfModule> |
| 304 | |
| 305 | a2ensite lms-ssl.conf |