Non-www domain pointing to /var/www/html?

Hi there, I’m running a fresh install of Ubuntu 14.04 LTS on Digitalocean. It’s a fresh installed and I have tried re-imaging a couple of times to rule out any server issues.

So basically, I have set up a virtual server “techsite.cf” in Virtualmin. DNS records are handled by Digitalocean and I have forwarded both “techsite.cf” and “www.techsite.cf” to my site’s IP address.

Now, the issue is that “www.techsite.cf” points correctly to /home/techsite/public_html, whereas techsite.cf points to /var/www/html instead. It seems that the former is following the correct VirtualHost file whereas the latter is following the “000-default.conf” VirtualHost file instead.

I am intrigued as to what could be wrong. When I unlink the 000-default.conf file, it seems to work fine, but shouldn’t the non-www and www work out of the box?

Here is 000-default.conf and techsite.cf.conf respectively:

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost *:80>
SuexecUserGroup "#1000" "#1000"
ServerName techsite.cf
ServerAlias www.techsite.cf
ServerAlias webmail.techsite.cf
ServerAlias admin.techsite.cf
DocumentRoot /home/techsite/public_html
ErrorLog /var/log/virtualmin/techsite.cf_error_log
CustomLog /var/log/virtualmin/techsite.cf_access_log combined
ScriptAlias /cgi-bin/ /home/techsite/cgi-bin/
ScriptAlias /awstats/ /home/techsite/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/techsite/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/techsite/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/techsite/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/techsite/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.techsite.cf
RewriteRule ^(.*) https://techsite.cf:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.techsite.cf
RewriteRule ^(.*) https://techsite.cf:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "techsite.cf statistics"
AuthType Basic
AuthUserFile /home/techsite/.awstats-htpasswd
require valid-user
</Files>
</VirtualHost>

Any help would be greatly appreciated!

I did some more troubleshooting, and apparently non-www for my root site seems to be headed straight to 000-default.conf unless I set www.techsite.cf.

Now, since my domain is a free one, I decided to get another domain to test and see. Apparently, if I add the second domain, it works just fine without the www., and the 000-default.conf still acts as a catchall otherwise, which is my intended behaviour.

So, I’m guessing that Apache doesn’t play nice when the hostname matches exactly with the non-www name? :confused:

Hi there, I did even more testing and confirmed my hypothesis.

Under Webmin, if my hostname is ‘domain1.com’, then domain1.com will redirect to the Apache2 page and ‘www.domain1.com’, ‘domain2.com’ and ‘www.domain2.com’ works fine.

If my hostname is ‘www.domain1.com’, then www.domain1.com will redirect to the Apache2 page and the rest will work.

If my hostname is ‘domain2.com’, then domain2.com will redirect to the Apache2 page and the rest will work.

If my hostname is ‘www.domain2.com’, then www.domain2.com will redirect to the Apache2 page and the rest will work.

Now, my question is: Why will my hostname redirect to the Apache2 page if I leave 000-default.conf there?

Thank you!

Having similar problem

If I create more virtual servers there isnt any problems

The only problem is with the virtual server that is created with the server hostname

hostname = example.com
new virtual server = example.com
That equals pointing to var/www/html

Ive been looking like crazy someone out there that knows the answer

Thanks

Howdy,

It’s actually safe to remove the 000-default.conf file/VirtualHost if that’s causing problems. It sounds like it is in this case :slight_smile:

Once you remove that, and restart Apache, do things work as expected at that point?

-Eric

@andreycheck

Why didnt I think I that

That solved my problem, perfect thank so much

Yes, indeed that was the case and removing it does solve the problem.

However, I am curious as to why is there such an issue in the first place? Does the problem lie with Apache or Virtualmin’s configuration of Apache?

Thank you.

Just had to do this today on Debian 8 and Ubuntu 14.04 fresh setups.

What gives? Another system which I installed a few weeks ago with Ubuntu 14.04 did not have the problem.

Is it hostname related in someway when we first setup the servers??

Thank you @andreychek

I went through a lot of pain until reading your answer!! :slight_smile:

Virtualmin, if using virtual servers, should have this covered by deafult i guess!

Thanks once again!

Cheers