Wednesday, February 11, 2015

apache 2.2 - Apache2 Default overrides virtual host




I have an Ubuntu 12.10 LTS server running apache2 with a simple wordpress install. I created the virtual host in /etc/apache2/sites-available and used a2ensite to enable it. All was working fine for two days.



This morning I woke up to check the site and it seemed the virtual host was not working at all. It kept going to the default site in apache2.



Here is my config:



default




ServerAdmin webmaster@localhost


DocumentRoot /var/www

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny

allow from all


ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all



ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"


Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128






virtual host: domain.com




ServerAdmin me@domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /srv/www/domain.com/public_html/
ErrorLog /srv/www/domain.com/logs/error.log
CustomLog /srv/www/domain.com/logs/access.log combined




As you can see I have two separate configs with no conflicts. But apache2 keeps reverting to the default site instead of the name-based vhost. My /etc/hosts file is correct and has a FQDN and host name pointed to the public-facing IP as well. This just happened overnight.



I ran a a2dissite on domain.com, apache2 reload, then a2ensite on domain.com with no results. I ended up having to a2dissite the default config. Once I did that the domain.com site came up with my wordpress site just fine.



Any idea why this happened? I've ran apache2 and nginx for years and have never had a problem with virtual hosting. This one is a bit weird. I shouldn't have to disable the default site for my other virtual host to work.



Any thoughts?



Answer



Try adding




ServerName localhost




into the default virtual host. Also you could temporarily disable the < Directory / > section from the default virtual host, it seems to be useless.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...