Thursday, April 4, 2019

apache 2.2 - Close access to website by http://ip, but allow by http://domain



I have to close access to website by ip (close access via http://203.0.113.11), but access via domain should be still available.



I've read http://httpd.apache.org/docs/2.0/vhosts/name-based.html (section Using Name-based Virtual Hosts), configured as recommended:




NameVirtualHost *:80


ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain




restarted httpd, but this VirtualHost is still available by ip.



What am I doing wrong?


Answer



Your apache will always use the first virtualhost as the default one.



So before any other vhosts, create another one that points to whichever you want to show all visitors hitting a hostname that doesn't exist within a virtualhost config.


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...