Tuesday, March 3, 2015

Install apache2 server with mod_ssl and dedicated subdomain

First install apache2 webserver firing following command on your terminal:
>sudo apt-get install apache2 
 
 
Step 1 : Create a  ".conf " file in sites-available. 

> cd /etc/apache2/sites-available
> nano test.mydomaine.com.conf
 
Step 2 :

Insert following content in test.mydomaine.com :
 
 <VirtualHost *:80>
        ServerAdmin mymail@gmail.com        //your server email id
        ServerName  test.mydomaine.com      //your domain name
        ServerAlias www.test.mydomaine.com  // alias if you want its optional
        DocumentRoot /var/www/testfolder/   //your root folder if default no change needed
<Directory "/var/www/testfolder">
        AuthType Basic
        AuthName "test"
        AuthUserFile /var/www/testfolder/passwords
        Require valid-user test
</Directory>
</VirtualHost> 
 
Step 3 : Enabling the domain
  
 
      > a2ensite test.mydomaine.com 
> sudo service apache2 reload  

Step 4 : Enable mod_ssl or https feature for your domain name
 
>sudo a2enmod ssl           // it will enable mod_ssl feature  
>sudo a2ensite default-ssl  //it will configure apache2 for https 
>sudo service apache2 restart 

Note : If you want to add a certificate for your website you can change the path in /etc/apache2/sites-available/default-ssl.conf

 
 
Step 5 : Configure DNS resolution for the new hostname 
 
  • If you are just playing with this locally and do not want to create a "real" DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. 
  • If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1.
  •  If the browser is on a different machine on your local network, you'll need to determine the server's IP address and then on the browser machine, edit /etc/hosts to add the mapping.
  • For Windows, the file is called C:\windows\system32\drivers\etc\hosts
  •  A sample entry would be (for the browser running on the same machine as the server):
    127.0.0.1 test.mydomain.com
If the server is at, say 192.168.0.5, the entry would be:
192.168.0.5 test.mydomain.com
  • If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server's real IP instead of 127.0.0.1. Do this on the system where you are running the browser.
 
 
 
 
 



No comments:

Post a Comment