# Apache issue with default site.



## Hxxx (Mar 12, 2014)

Hi Folks,

Don't know what step I'm missing this time.

Here is what I've done:

1- Disabled default apache site.

2- Create desired apache site

3- Enabled desired apache site.

4- Restart Apache

Since the above doesn't prevent apache from serving the website when being accessed directly through IP, that is: http://IP I went to:

1- Enabled default apache site

2- Created a different folder

3- Pointed default apache site to a different folder.

4- Restart Apache

http://IP still pointing to the new site folder.

Other than using .htaccess to prevent access from IP, am I missing something?

I can create different sites, to different folders, different servernames and they work perfectly each one serving their own folder. But http://IP still point to the first site conf I created.

Must be missing something here. Apache is 2.4

I'll appreciate the help.


----------



## johnlth93 (Mar 12, 2014)

they are loaded accordingly, by default the first <VirtualHost> will be served unless explicitly told otherwise.


----------



## sv01 (Mar 12, 2014)

try


<VirtualHost YOUR.IP.GOES.HERE>
DocumentRoot "/var/www/html"
RewriteEngine On
RewriteCond %{HTTP_HOST} !^myuglydomain.com$
RewriteRule /.* http://myuglydomain.com/ [R]
</VirtualHost>

*sh** code not work


----------



## Hxxx (Mar 12, 2014)

Guys thank you for the reply, but I think that maybe I was not clear enough.

I just dont want the vps to server any virtualhost when accessed through IP.

So if someone goes and type: http://IP-HERE it should deny or just dont work.


----------



## tortau (Mar 12, 2014)

Use:


sudo apachectl -S
You will see the list of configuration loaded (the default and vhosts, as well as the config location/line number). It should help debug things...


----------



## tchen (Mar 12, 2014)

hrr1963 said:


> Since the above doesn't prevent apache from serving the website when being accessed directly through IP, that is: http://IP I went to:
> 
> 1- Enabled default apache site
> 
> ...


When you re-enabled the default, make sure it's 00-default in sites-enabled.  Also ensure it has no ServerName that would otherwise preclude it from being used.


----------



## Leo (Mar 12, 2014)

johnlth93 said:


> they are loaded accordingly, by default the first <VirtualHost> will be served unless explicitly told otherwise.


This.

I have the follwing set as first VirtualHost in the apache config:


<VirtualHost *:80>
ServerAdmin [email protected]
ServerName default.blackhole

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
deny from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/blackhole-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/blackhole-access.log combined
ServerSignature Off
</VirtualHost>

Then I have the VirtualHosts for my sites. This will return permission denied to anyone accessing the webserver with just IP or with a unknown hostname.


----------



## mojeda (Mar 12, 2014)

Apache will load whatever virtual host file is first as the "default" website.


----------



## Hxxx (Mar 13, 2014)

Solved as some of you pointed out: I disabled all sites conf except one, and there I configured all websites, and the first vhost there i pointed it to an empty folder. So yes it works 

Thank you.


----------

