Walter H.
2017-Nov-13 11:31 UTC
[CentOS] Strrange behavior of VirtualHosts in Apache (CentOS6)
Hello, there is a short explanation about virtual hosts in Apache ... https://wiki.centos.org/TipsAndTricks/ApacheVhostDefault the `hostname` gives a different donmain name than what should be hosted ... e.g. `hostname` is host.example.org and the domain to be hosted is example.com, so I did this: <VirtualHost 1.2.3.4:80> ServerName host.example.org DocumentRoot /var/www/default </VirtualHost> # used to get let's encrypt for the mail server <VirtualHost 1.2.3.4:80> ServerName mail.example.org ServerAlias smtp.example.org DocumentRoot /var/www/mail </VirtualHost> <VirtualHost 1.2.3.4:80> ServerName www.example.com DocumentRoot /var/www/domain </VirtualHost> <VirtualHost 1.2.3.4:80> ServerAlias *.example.com DocumentRoot /var/www/catchall </VirtualHost> the DocumentRoot directories are empty, only in /var/www/default I have a PHP script: host.php <?php header( "Content-type: text/plain" ); printf( "Host: '%s'\n", $_SERVER['HTTP_HOST'] ); ?> now the strange behavior; http://mail.example.org/ <-- works http://smtp.example.org/ <-- doen't work http://smtp.example.org/host.php <-- gives the HTTP_HOST (PHP-script), but why? http://www.example.com/ <-- works http://hello.example.com/ <-- doesn't work http://hello.example.com/host.php <-- gives the HTTP_HOST (PHP-script), but why? doesn't work does mean, that access/errors are logged in logfile of wrong virtual host ... where is my mistake; Thanks, Walter
Joseph L. Casale
2017-Nov-13 14:54 UTC
[CentOS] Strrange behavior of VirtualHosts in Apache (CentOS6)
-----Original Message----- From: CentOS [mailto:centos-bounces at centos.org] On Behalf Of Walter H. Sent: Monday, November 13, 2017 4:32 AM To: centos at centos.org Subject: [CentOS] Strrange behavior of VirtualHosts in Apache (CentOS6)> Hello, > > there is a short explanation about virtual hosts in Apache ... > https://wiki.centos.org/TipsAndTricks/ApacheVhostDefaultThat page has not been updated since 2009, while it may be correct there is no reason not to use the correct documentation, the section of interest is short: https://httpd.apache.org/docs/2.4/vhosts/name-based.html> <VirtualHost 1.2.3.4:80> > ServerName host.example.org > DocumentRoot /var/www/default > </VirtualHost>So this becomes your default vhost when a match is not found and explains why the php file is invoked when the order of specificity falls through.> http://mail.example.org/ <-- works > http://smtp.example.org/ <-- doen't work > http://smtp.example.org/host.php <-- gives the HTTP_HOST (PHP-script), > but why? > > http://www.example.com/ <-- works > http://hello.example.com/ <-- doesn't work > http://hello.example.com/host.php <-- gives the HTTP_HOST (PHP-script), > but why?Do you have the correct ip address in your vhost config? I would bet if you read the log, you will see what is happening and how it differs from what you expect. Some more in-depth details at https://httpd.apache.org/docs/2.4/vhosts/details.html
Walter H.
2017-Nov-14 08:52 UTC
[CentOS] Strrange behavior of VirtualHosts in Apache (CentOS6)
On Mon, November 13, 2017 15:54, Joseph L. Casale wrote:> -----Original Message----- > From: CentOS [mailto:centos-bounces at centos.org] On Behalf Of Walter H. > Sent: Monday, November 13, 2017 4:32 AM > To: centos at centos.org > Subject: [CentOS] Strrange behavior of VirtualHosts in Apache (CentOS6) > >> Hello, >> >> there is a short explanation about virtual hosts in Apache ... >> https://wiki.centos.org/TipsAndTricks/ApacheVhostDefault > > That page has not been updated since 2009, while it may be correct > there is no reason not to use the correct documentation, the section > of interest is short: > https://httpd.apache.org/docs/2.4/vhosts/name-based.html>> <VirtualHost 1.2.3.4:80> >> ServerName host.example.org >> DocumentRoot /var/www/default >> </VirtualHost> > > So this becomes your default vhost when a match is not found and explains > why the php file is invoked when the order of specificity falls through. > >> http://mail.example.org/ <-- works >> http://smtp.example.org/ <-- doen't work >> http://smtp.example.org/host.php <-- gives the HTTP_HOST (PHP-script), >> but why? >> >> http://www.example.com/ <-- works >> http://hello.example.com/ <-- doesn't work >> http://hello.example.com/host.php <-- gives the HTTP_HOST (PHP-script), >> but why? > > Do you have the correct ip address in your vhost config?yes> I would > bet if you read the log, you will see what is happening and how it differs > from > what you expect.not really, the strange thing was something different; httpd -S lists all vhosts, and at last 'Syntax OK' and exact this was the strange; I'm used to add the port number to ServerAlias and this was the mistake ... httpd -S, didn't realize this I removed the port numbers from ServerAlias entries and now it works :-)> Some more in-depth details at > https://httpd.apache.org/docs/2.4/vhosts/details.htmlGreetings, Walter