What I'm trying to do is to show a page when a domain is visited but if someone tries to visit directly by ip (and not using the domain) i want to show him another page.
Classic name based apache hosting right?
Well my only question is what should i put in ServerName and/or ServerAlias?
What i've done till now is to uncomment this line:
NameVirtualHost *:80
and i've setup 2 virtual hosts like this (specific info hidden):
<VirtualHost *:80>
ServerAdmin someone@gmail.com
DocumentRoot /var/www/vhosts/default/
ServerName {my-dedicated-ip}
ErrorLog /var/www/vhosts/default/error.log
CustomLog /var/www/vhosts/default/custom.log gk
</VirtualHost>
<VirtualHost *:80>
ServerAdmin some-email@valid-domain.com
DocumentRoot /var/www/vhosts/something/httpdocs/
ServerName valid-domain.com
ServerAlias *.valid-domain.com
ErrorLog "| /usr/sbin/rotatelogs -l /var/www/vhosts/something/logs/error.log.%Y.%m.%d 86400"
CustomLog "| /usr/sbin/rotatelogs -l /var/www/vhosts/somthing/logs/custom.log.%Y.%m.%d 86400" gk
</VirtualHost>
but unfortunately it doesn't work.
Thanks in advance.
EDIT: Oh, and i have a single dedicated ip.
I also just found this: How can I get Apache to not respond to an IP-only request? according to which, my setup should work. It should visit the first vhost it finds. But it doesn't. It goes to the second.
EDIT: apachectl -S output:
[root@me conf.d]# apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server domain.com (/etc/httpd/conf/httpd.conf:1015)
port 80 namevhost {my-dedicated-ip} (/etc/httpd/conf/httpd.conf:1015)
port 80 namevhost valid-domain.com (/etc/httpd/conf/httpd.conf:1023)
wild alias *.vaild-domain.com
Syntax OK
and yes the 2 vhosts are in the same file.
apachectl -S
? – etagenklo Jun 30 '14 at 11:25