我在ubuntu 14.04上运行apache2,并使用Let's Encrypt设置了SSL。
在我的域名之一(域名A)它工作正常。 我可以达到它
http://domainA.com http://www.domainA.com
要么
https://domainA.com https://www.domainA.com
但是,我有附加的域指向框,并为每个这样的虚拟服务器设置。 我以同样的方式设置domainA( 如果您想知道如何使用,请参阅本教程 )
在我的其他网域上,通过https的stream量显示了正确的虚拟内容 – 但是通过http的stream量只显示了根目录(所以默认的index.html出现)。
在/ etc / apache2 /网站,可用我有以下几点:
000-default.conf default-ssl.conf domainA.com.conf domainA.com-le-ssl.conf domainB.com.conf domainB.com-le-ssl.conf
它们的设置完全相同,只是相关的信息发生了变化。
domainA .conf如下所示:
<VirtualHost *:80> ServerAdmin [email protected] 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看起来完全相同,除了用“domainB”代替domainA。 domainA.com-le-ssl.conf文件看起来几乎完全相同,除了包括所有合适的SSL文件并且在端口443上(当我使用Let's Encrypt创build文件时,它是dynamic生成的 – 我没有碰到它们)
所以domainB.conf看起来像这样:
<VirtualHost *:80 ServerAdmin [email protected] 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看起来像这样(与仅改变相关名称的DomainA相同):
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin [email protected] 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>
在domainA上的http和https没有问题,两者都显示相同的事情。
在domainB上的http把我带到/ var / www / html
在domainB上的https将我带到/ var / www / html / domainB / public_html(按照预期)
DNS正在指向我的服务器正确的域 – 所以我不认为这是一个DNS问题一样多的configuration或可能是SSL的问题?
只是想知道为什么和/或如何改变这种情况? 有没有人有任何想法,为什么它可能在第一个工作,但没有其他人?
我觉得它正在为HTTPstream量拾取000-default.conf。
我的000-default.conf如下所示:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
所以显然在某些时候,网站的HTTP版本已经被禁用(可能在启用HTTPS版本时)。
一旦我做了以下工作,他们正在通过端口80和端口443(分别http和https):
sudo a2ensite domainB.com.conf
然后我会重新加载Apache这个:
sudo service apache2 reload
然后,它将获取该网站的HTTP版本的configuration,并适当地引导它。
我决定我希望所有stream量都被迫使用HTTPS – 所以我在HTTP conf(/etc/apache2/sites-available/domainB.com.conf)中添加了以下行:
Redirect permanent / https://domainB.com
现在,如果有人试图从HTTP到达这个网站,它会把它们引导到适当的位置。
希望这可以帮助别人:)