http-трафик, показывающий другой каталог, чем https-трафик на apache

I have apache2 running on ubuntu 14.04 and had set up SSL using Let's Encrypt.

On one of my domains (domainA) it works fine. I can reach it at

http://domainA.com
http://www.domainA.com

or

https://domainA.com
https://www.domainA.com

However I have additional domains point at the box and have setup virtual servers for each of these. I set them up in the same way I setup domainA (see this tutorial if you're wondering how)

On my additional domains traffic over https displays the right dummy content - but traffic over http just shows me the root directory (so the default index.html shows up).

in /etc/apache2/sites-available I have the following:

000-default.conf
default-ssl.conf
domainA.com.conf
domainA.com-le-ssl.conf
domainB.com.conf
domainB.com-le-ssl.conf

They are all setup identically with only the pertinent information changed.

domainA .conf looks like this:

<VirtualHost *:80>
    ServerAdmin me@domainA.com
    ServerName domainA.com
    ServerAlias www.domainA.com
    DocumentRoot /var/www/html/domainA/public_html

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

domainB.conf looks identical except with 'domainB' substituted instead of domainA. The domainA.com-le-ssl.conf file looks almost identical except for including all appropriate SSL files and being on port 443 (it's generated dynamically when I create the file with Let's Encrypt - I haven't touched them)

So domainB.conf looks like this:

<VirtualHost *:80
    ServerAdmin me@domainB.com
    ServerName domainB.com
    ServerAlias www.domainB.com
    DocumentRoot /var/www/html/domainB/public_html

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

DomainB.com-le-ssl.conf looks like this (identical to DomainA with only pertinent names changed):

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin me@domainB.com
    ServerName domainB.com
    ServerAlias www.domainB.com
    DocumentRoot /var/www/html/domainB/public_html

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

SSLCertificateFile /etc/letsencrypt/live/domainB.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domainB.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/domainB.com/chain.pem
</VirtualHost>
</IfModule>

http and https on domainA work with no issue, both showing the same thing.

http on domainB takes me to /var/www/html

https on domainB takes me to /var/www/html/domainB/public_html (as intended)

DNS is pointing to my server fine for the appropriate domains - so I don't think it's a DNS issue as much as an issue with the configs or maybe the SSL?

Just wondering as to why and/or how I can change that? Does anyone have any ideas why it might have worked on the first one but for none of the others?

I feel like it's picking up 000-default.conf for HTTP traffic.

My 000-default.conf looks like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1
задан 2 January 2017 в 16:22
1 ответ

Очевидно, что в какой-то момент HTTP-версия сайтов стала отключена (потенциально при включении версии HTTPS).

После того, как я сделал следующее, они работали и над портом 80 и над портом 443 (http и https соответственно):

sudo a2ensite domainB.com.conf

Тогда я бы перезагрузил apache с этим:

sudo service apache2 reload

Тогда бы он подобрал конфигурацию для HTTP-версии сайта и направил бы его соответствующим образом.

Я решил, что хочу, чтобы весь трафик был вынужден использовать HTTPS - поэтому я добавил следующую строку в HTTP conf (/etc/apache2/sites-available/domainB.com.conf)

Redirect permanent / https://domainB.com

Теперь, если кто-то пытается попасть на сайт с HTTP, он направляет его в соответствующее место.

Надеюсь, это поможет кому-нибудь другому :)

.
2
ответ дан 3 December 2019 в 20:31

Теги

Похожие вопросы