0

I'm currently using name-based virtual host configuration /conf/extra/httpd-vhosts.conf in apache to serve few different websites from the same IP address, just like in the apache documentation.

<VirtualHost *:80>
ServerName domain1.example.com
DocumentRoot /www/domain1
</VirtualHost>

<VirtualHost *:80>
ServerName domain2.example.com
DocumentRoot /www/domain2
</VirtualHost>

If I try to open a web site, that is configured in /conf/httpd.conf, defined by directive ServerName, which is basically FQDN of Linux server, I'm getting the very 1st page defined in /conf/extra/httpd-vhosts.conf - apache is acting that DNS name does not match any ServerName defined, therefore I'm getting the 1st one from /conf/extra/httpd-vhosts.conf.

If I change the directive Listen in /conf/httpd.conf to a different port (from that defined in /conf/extra/httpd-vhosts.conf; I'm using standard port 80) and then try to hit http://ServerName:Port (Port defined in Listen - I used 8000 for testing purpose), I'm getting content of web site configured in /conf/httpd.conf (ServerRoot), which is what I want.

I tried to change the port defined in /conf/extra/httpd-vhosts.conf to match it with that one temporary configured in /conf/httpd.conf e.g.:

<VirtualHost *:8000>
ServerName domain1.example.com
DocumentRoot /www/domain1
</VirtualHost>

<VirtualHost *:8000>
ServerName domain2.example.com
DocumentRoot /www/domain2
</VirtualHost>

Now, when I hit http://ServerName:Port (port = 8000), apache again gives me 1st web site from /conf/extra/httpd-vhosts.conf - domain1.example.com

I tried to update directives Listen (in /conf/httpd.conf) with server IP, IP:port but it does not work either.

My server has DNS A record, web sites in /conf/extra/httpd-vhosts.conf are configured in DNS as ALIAS records for server A record.

EDIT:

Adding ouput of apachectl -S:

VirtualHost configuration:
*:80                 is a NameVirtualHost
         default server domain1.example.com (/appl/apache24/conf/extra/httpd-vhosts.conf:24)
         port 80 namevhost domain1.example.com (/appl/apache24/conf/extra/httpd-vhosts.conf:24)
                 alias domain1.example.com
         port 80 namevhost domain2.example.com (/appl/apache24/conf/extra/httpd-vhosts.conf:38)
                 alias domain2.example.com
ServerRoot: "/appl/apache24"
Main DocumentRoot: "/appl/apache24/htdocs"
Main ErrorLog: "|/appl/apache24/bin/rotatelogs /appl/apache24/logs/admin-error_log.%Y%m%d 86400"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/appl/apache24/logs/" mechanism=default
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/appl/apache24/logs/httpd.pid"

EDIT2:

Adding output of apachectl -V:

Server version: Apache/2.4.23 (Unix)
Server built:   Sep 21 2016 11:23:28
Server's Module Magic Number: 20120211:61
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/opt/app/workload/apache24"
 -D SUEXEC_BIN="/opt/app/workload/apache24/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
ray
  • 41
  • 9
  • Please add the output from the following command to your question `apachectl -S` on some systems it will be `apache2ctl -S` – Unbeliever Oct 13 '16 at 16:09
  • So it looks from the output that the virtual host in `conf/httpd.conf` is not being read. You can test is a file i sbeing read at all buy putting `any old rubbish` in it and running `apachectl configtest`. You will get an error if it is. – Unbeliever Oct 18 '16 at 11:09
  • I though that too, but I checked that already - both `conf/httpd.conf` and `conf/extra/httpd-vhosts.conf` are being read and processed. There must be something else I'm missing and I can't figure it out. – ray Oct 18 '16 at 11:27
  • The `apachectl -S` command really is one of the most basic things you can do. If it is not working as I describe then either you have either made a mistake or your Apache installation is broken in some basic way. If `apachectl -S` was released broken it would be noticed by many 1000's of admins around the world. So I'm not sure what to say other than please verify conf/httpd.conf is actually being read again. Could you also add the output of `apachectl -V` to your post for completeness? – Unbeliever Oct 18 '16 at 12:03
  • I also tried your approach - after adding dummy text into both configuration files (one by one), verification pointed to this dummy text as error. I added output of `apachectl -V` command. And to be honest, apache was installed 2 times - 1st time it was installed without _openldap-devel_, 2nd time it was installed with this package. Do you think this might be a problem? – ray Oct 18 '16 at 12:12
  • Well if you have two versions, you have to be very careful about which you are modifying for sure :) As per the output of `apachectl -V`, the conf `httpd.conf` you should be modifying is `/opt/app/workload/apache24/conf/httpd.conf` as long as you are using the same `apachectl` to stop/start/restart your Apache. – Unbeliever Oct 18 '16 at 13:12
  • Well, the 2nd installation just re-installed the 1st installation - I'm using only one instance of apache. And `/appl` is just a symbolic link for `/opt/app/workload` – ray Oct 18 '16 at 13:30
  • All I can really say at this point is if apache find `` tags in the configuration files it reads it will always output something about them in the output of `apachectl -S`. I would really advise cleaning up you apache installs, so that only 1 is present, before proceeding. – Unbeliever Oct 18 '16 at 14:49
  • I tried the same setup on different server - same behavior. What I did is, that I defined the default web (the one accessible by specifying the server name or server IP) site in `httpd-vhost.conf` file to cover it. I just still don't understand, why the web site definition in `httpd.conf` does not work - as soon as I comment `include conf/extra/httpd-vhosts.conf` file in order not to include it, my default web site from `httpd.conf` is accessible. Thanks anyway @Unbeliever – ray Oct 26 '16 at 09:00

0 Answers0