Categories
Tag Cloud
Set up local domain names in Ubuntu comprehensive guide
- 5
-
Tired of reading? Press play to listen instead. N/B. Might not work on some articles
Ready
This article will show you a step by step guide on how to set up local domain names in Ubuntu
1.Add entry in /etc/hosts file
Edit your /etc/hosts file by adding you desirable local domain. By default, It looks something like this.
127.0.0.1 localhost127.0.1.1 HOSTNAME (Varies with computer)
# The following lines are desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allrouters
I will add sinosoft.local to my hosts file, final etc example will look as below
127.0.0.1 localhost127.0.0.1 HOSTNAME
127.0.0.1 sinosoft.local
N/B you may add as many local domains as you wish
2.Create Virtual hosts in Apache
Create a file e.g sinosoft.conf in Apache’s virtual host configuration directory using the following command.
$ sudo nano /etc/apache2/sites-available/sinosoft.conf
3. Add this configuration in the Apache Virtual Host application you have created above
<VirtualHost *:80>
ServerAdmin root@sinosoft.localServerName sinosoft.localDocumentRoot /path/to/project/sinosoft.local/public_html
ErrorLog /var/log/apache2/sinosoft-error.logCustomLog /var/log/apache2/sinosoft-access.log combined
</VirtualHost>
4. Enable Site and Reload Apache using these commands
$ sudo a2ensite sinosoft.conf$ sudo service apache2 reload
How to create a Virtual Host in Nginx
Creating Virtual Host in Nginx is the same process but the syntax of Nginx configuration are very different than Apache. To do so run the below command
$ sudo nano /etc/nginx/sites-available/sinosoft.conf the add the following code in the file you just created
server {
listen 80;server_name sinosoft.localroot /path/to/project/sinosoft.local/public_html
access_log /var/log/nginx/sinosoft-access.conferror_log /var/log/nginx/sinosoft-error.log
}
Activate Site using the below commands
$ sudo ln -s /etc/nginx/sites-available/sinosoft.conf /etc/nginx/sites-enabled/sinosoft.conf$ sudo service nginx reload
N/B If you using Chrome browsser, do not use .dev domain name as Google Chrome will force redirect the URL from http to https.
Conclusion
To test if your configuration is working go to your browser and type your domain name in my case sinosoft.local.
Credits: Interserver