2

I have a litle problem with my virtual host configuration on Apache2.

Context : I have a Raspberry Pi with Apache2 installed. I want to access to my test directory in : "/var/www/html/test".

So I modified my 000-default.conf in "/etc/apache2/sites-available" like this and this worked:

 <VirtualHost *:80>

            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html

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

    </VirtualHost>


    NameVirtualHost 192.168.1.29:80

    <VirtualHost 192.168.1.29:80>
    ServerName raspyvan
    DocumentRoot /var/www/html/test
    </VirtualHost>



    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

(raspyvan is my servername on my router ans host file)

But I would deny the access with IP adress "192.168.1.29"

So I modified in a second time my 000-default.conf file like this :

Listen 192.168.1.29:80

ServerName DefaultServer
DocumentRoot /var/www/html

NameVirtualHost 192.168.1.29:80


<VirtualHost 192.168.1.29:80>
        ServerName 192.168.1.29

        <Directory />
                Deny from all
        </Directory>
</VirtualHost>


<VirtualHost 192.168.1.29:80>
                ServerName raspyvan
                DocumentRoot /var/www/test
</VirtualHost>



# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Now the problem is that the access by IP and hostname are denied and I don't know why.

Edit : My nameserver is apply on the DNS router config and hosts apache file.

1 Answer 1

0

when apache can't match a vhost it will always use the first vhost it comes across (this is why we historically needed one ip per ssl cert until sni came along).

add a log per vhost;

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

and

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

check the log file "access-default.log" to see which hostname has been requested.

6
  • Thanks. I have add log per vhost but these files are not created when I request on browser. These files are in "/var/log/apache2/" ?
    – Yvan
    Commented Nov 23, 2016 at 21:05
  • did you restart or reload apache? if so they'll be in /var/log/apache2 Commented Nov 23, 2016 at 22:47
  • Yes I have restart the apache service but no file are create. Moreover in other log files there are no log about the deny access.
    – Yvan
    Commented Nov 24, 2016 at 13:13
  • CustomLog /var/log/apache2/access-raspyvan.log combined use full path and try Commented Nov 26, 2016 at 11:57
  • 1
    Can you add an edit with the latest config you have, will tweek and put in an update to answer. Commented Nov 29, 2016 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .