0

downloads.example.net is being ignored by my configuration. I created it as an additional virtual host to the existing hosts for file downloads. Made a folder, set permissions, set up two virtual hosts, one for HTTP to rewrite to HTTPS and the other for HTTPS. Already have a virtual host to serve people hitting the IP, I do not want to show them anything so serve a blank page on the IP, no rewards for coming directly. There is a WordPress site served on a couple of domain, same set up, rewrite to HTTPS.

Come on the IP and get the blank index.html on /var/www/html. Come on www.example.net, www.example.info, example.net and example.info and get the WordPress website. Come on downloads.example.net either on HTTP or HTTPS and get the WordPress website. I do not normally have multiple domains on virtual hosts or use rewrites to move people to SSL so wonder if I've gone wrong there.

SSL certs are shared between sites as CloudFlare add their own cert to users accessing the site.

<VirtualHost *:80>
    ServerName 111.222.233.244
    ServerAdmin support@localhost
    DocumentRoot /var/www/html

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

<VirtualHost *:80>
    ServerName downloads.example.net
    ServerAlias downloads.example.info
    ServerAdmin support@example.net
    DocumentRoot /var/www/downloads

    ErrorLog ${APACHE_LOG_DIR}/downloaderror.log
    CustomLog ${APACHE_LOG_DIR}/downloadaccess.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.net
    ServerAlias example.net
    ServerAlias www.example.info
    ServerAlias example.info
    ServerAdmin support@example.net
    DocumentRoot /var/www/wordpress

    ErrorLog ${APACHE_LOG_DIR}/exampleerror.log
    CustomLog ${APACHE_LOG_DIR}/exampleaccess.log combined
</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost *:443>
    ServerName 111.222.233.244
    ServerAdmin support@localhost
    DocumentRoot /var/www/html

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

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>
    BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  </VirtualHost>

  <VirtualHost *:443>
    ServerName downloads.example.net
    ServerAlias downloads.example.info
    ServerAdmin support@example.net
    DocumentRoot /var/www/downloads

    ErrorLog ${APACHE_LOG_DIR}/downloaderror.log
    CustomLog ${APACHE_LOG_DIR}/downloadaccess.log combined

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  </VirtualHost>

  <VirtualHost *:443>
    ServerName www.example.net
    ServerAlias example.net
    ServerAlias www.example.info
    ServerAlias example.info
    ServerAdmin support@example.net
    DocumentRoot /var/www/wordpress

    ErrorLog ${APACHE_LOG_DIR}/exampleerror.log
    CustomLog ${APACHE_LOG_DIR}/exampleaccess.log combined

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  </VirtualHost>
</IfModule>

EDIT:

First suggestion to add IP to first directive does nothing, the first one was not the one being served but the one with the domain in it. The second and third comment has a link to a "duplicate", the suggestions on that page are followed below.

apache2ctl -t
Syntax OK

apache2ctl -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server 111.222.233.244 (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost 111.222.233.244 (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost downloads.example.net (/etc/apache2/sites-enabled/000-default.conf:10)
             alias downloads.example.info
     port 80 namevhost www.example.net (/etc/apache2/sites-enabled/000-default.conf:25)
             alias example.net
             alias www.example.info
             alias example.info
*:443                  is a NameVirtualHost
     default server 111.222.233.244 (/etc/apache2/sites-enabled/000-default.conf:43)
     port 443 namevhost 111.222.233.244 (/etc/apache2/sites-enabled/000-default.conf:43)
     port 443 namevhost downloads.example.net (/etc/apache2/sites-enabled/000-default.conf:67)
             alias downloads.example.info
     port 443 namevhost www.example.net (/etc/apache2/sites-enabled/000-default.conf:93)
             alias example.net
             alias www.example.info
             alias example.info
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Disabled SSL and tried port 80 with only two hosts but downloads still gets sent to example.net.

<VirtualHost *:80>        
    ServerName downloads.example.net
    ServerAdmin support@example.net
    DocumentRoot /var/www/html

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

<VirtualHost *:80>
    ServerName example.net
    ServerAlias www.example.net
    ServerAdmin support@example.net
    DocumentRoot /var/www/wordpress

    ErrorLog ${APACHE_LOG_DIR}/ufoerror.log
    CustomLog ${APACHE_LOG_DIR}/ufoaccess.log combined
</VirtualHost>
Peter Bushnell
  • 918
  • 1
  • 13
  • 30
  • Try putting `ServerName` followed by the IP address in the first VirtualHost block – neuhaus Aug 30 '17 at 21:16
  • Duplicate of https://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration – neuhaus Aug 30 '17 at 21:20
  • Possible duplicate of [How to debug an apache virtual host configuration?](https://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration) – neuhaus Aug 30 '17 at 21:20
  • The IP does not make a difference and that directive is not the one being served, the links are not duplicates of my post. The commands to check syntax and show virtual hosts seem to show that the configuration is correct. downloads.example.net serves the example.net virtual host and I cannot figure out why. Responses added to original post. – Peter Bushnell Aug 31 '17 at 06:49
  • is the redirect for port 80 working? – neuhaus Aug 31 '17 at 06:57
  • I removed the redirect to see if it was creating problems but downloads.example.net still gets sent to example.net. I've also removed the .info domain. The redirect was working well, port 80 got redirected to SSL as expected. – Peter Bushnell Aug 31 '17 at 07:06

1 Answers1

0

Try running apache in debug mode with the -X flag, then run your request to see what goes on.

Also increase the loglevel.

neuhaus
  • 3,886
  • 1
  • 10
  • 27