[英]SSL for subdomain is allowing parent domain to redirect to subdomain
我已經為我的子域啟用了SSL,並且一切正常。 我遇到的問題是,當您在父域中包含https(不應允許SSL連接)時,它會作為父級重定向到子域。
我假設我的虛擬主機條目中有不正確的內容。
有什么想法嗎?
謝謝
您沒有提供很多詳細信息,但是這里是開始。
當您指定HTTPS://<hostname>
,TCP消息將發送到<ip address>:443
。 不是<hostname>:443
。 您的瀏覽器在發送任何內容之前先進行主機名-> IP地址轉換。 您的瀏覽器還會在(加密的)消息中附加標頭Host: <hostname>
。
僅在解壓縮加密消息時,Web服務器才會獲取Host標頭,然后(可能)將其路由到其他虛擬主機。
但是在解密時,它已經在與SSL虛擬主機通信(否則,Apache無法解密該消息)。 因此,此時,它嘗試(通過Hosts標頭)找出“所需的”主機名是什么,然后查看您是否具有該名稱的:443虛擬主機。 如果不是,它將交給默認的:443虛擬主機。
假設 :
我還假設當您說“重定向到作為父級的子域”時,您的意思是應該只出現在HTTPS子域(即https://sub.example.com)上的內容才出現在HTTPS父域(即https://example.com看起來完全像https://sub.example.com),並且沒有發生真正的HTTP重定向
然后 :
如果您有兩個虛擬主機條目,如下所示:
<VirtualHost *:80>
# using parent content
DocumentRoot "/web/parent"
</VirtualHost>
<VirtualHost *:443>
#using subdomain content
DocumentRoot "/web/subdomain"
# All sorts of SSL config
....
</VirtualHost>
這將導致無論您使用什么主機名:
所以:
嘗試添加“ NameVirtualHost *:443”(如果尚未添加)和至少第三個VirtualHost:
NameVirtualHost *:443
<VirtualHost *:80>
# the default virtualhost for port 80
# using parent content
DocumentRoot "/web/parent"
</VirtualHost>
<VirtualHost *:443>
# the default virtualhost for port 443
# using subdomain content
ServerName sub.example.com
DocumentRoot "/web/subdomain"
# All sorts of SSL config
....
</VirtualHost>
<VirtualHost *:443>
# another virtualhost for port 443
# only activated for example.com like https://example.com/something
# using parent content
ServerName example.com
DocumentRoot "/web/parent"
# All sorts of SSL config
....
</VirtualHost>
評估順序很重要,因此對於與其他虛擬主機都不匹配的任何請求,第一個虛擬主機將成為默認主機。
當有人在父域上請求HTTPS時,無論您希望發生什么情況,都需要配置第三個虛擬主機:即,您是要重定向回HTTP版本,還是只顯示其他內容?
httpd命令具有-S標志,該標志將輸出當前排序的虛擬主機配置,然后退出,這對於診斷在哪些端口上定義了哪些虛擬主機以及相關的名稱很有用。
-S
Show the settings as parsed from the config file (currently only shows the virtualhost settings).
一些配置,版本和平台將對這個問題有所幫助。
ServerAdmin網站管理員@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.