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.

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.

  • 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 Nov 23 '16 at 21:05
  • did you restart or reload apache? if so they'll be in /var/log/apache2 – mikejonesey Nov 23 '16 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 Nov 24 '16 at 13:13
  • CustomLog /var/log/apache2/access-raspyvan.log combined use full path and try – mikejonesey Nov 26 '16 at 11:57
  • Thanks. But there are no log file created. I don't understand how apache work on vhost logs. – Yvan Nov 29 '16 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.