Reputation: 439
I want to create subdomains for every institute registered on my website.
I carried out following steps to create subdomains for a test website:
sudo a2enmod vhost_alias
sudo nano /etc/hosts
add line - 127.0.0.1 test.loc
sudo nano /etc/apache2/sites-available/testloc.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName test.loc
ServerAlias *.test.loc
VirtualDocumentRoot /var/www/html/test
<Directory "/var/www/html/test">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite testloc.conf
sudo service apache2 reload
sudo apt-get install dnsmasq
sudo service dnsmasq status
It gives error that port 53 is already in use so I changed its port to 5353
sudo nano /etc/NetworkManager/NetworkManager.conf
added line - dns=dnsmasq
sudo service network-manager restart
sudo nano /etc/dnsmasq.conf
modified line - listen-address=127.0.0.1
sudo nano /etc/dnsmasq.d/loc
added line - address=/loc/127.0.0.1
sudo /etc/init.d/dnsmasq restart
sudo nano /etc/dhcp/dhclient.conf
Uncommented line - #prepend domain-name-servers 127.0.0.1;
sudo dhclient
Created a test folder, added following lines in .htaccess to accept subdomains
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.test\.loc$
RewriteRule !^index\.php$ index.php [L]
Code of index.php:
preg_match('/([^.]+)\.test\.loc/', $_SERVER['SERVER_NAME'], $matches);
if(isset($matches[1])) {
$subdomain = $matches[1];
}
echo $subdomain;
I tried test.loc before creating Virtual Host and its working. The things were pretty fine before I installed dnsmasq. dig google.com is also not working after I installed dnsmasq, but "dig google.com @127.0.0.53" or "dig google.com @8.8.8.8" is also working. So it appears there's some issue with nameservers. Though I checked /etc/resol.conf, nameservers are enlisted there.
But somehow things not working. Can anyone bail me out of this?
Upvotes: 0
Views: 123
Reputation: 439
After hours of research it can be concluded that Ubuntu 17.04 is not a stable version, so dnsmasq (along with some others) is not working correctly.
I tested above process is working fine on Ubuntu 17.10 without any error.
Thanks
Upvotes: 0