2017-04-01 81 views
-1

我为我的子域启用了SSL,并且一切都很好。我遇到的问题是,当您为父域包含https(不应允许SSL连接)时,它将作为父域重定向到子域。子域的SSL允许父域重定向到子域

我假设我在我的虚拟主机条目中有些东西不正确。

有什么想法?

谢谢

+1

无论这些域是'子domains',两者都是顶级域。 –

+0

https前缀的含义是,浏览器在采取任何http内容之前需要ssl握手,包括重定向为http标头。该域的自签名证书对法律浏览器无效。 – Deadooshka

+0

我们可以看到你的'.htaccess'文件吗? –

回答

1

你没有提供很多细节,但这里是开始。

当您指定HTTPS://<hostname>时,TCP消息被发送到<ip address>:443。不是<hostname>:443。在发送任何内容之前,您的浏览器会执行主机名 - > IP地址转换。您的浏览器也会在(加密)消息中粘贴标头Host: <hostname>

只有在解包加密的消息时,web服务器才能获得主机头,然后(可能)将其路由到不同的虚拟主机。

但在解密时,它已经与SSL虚拟主机通话(否则,apache无法解密该消息)。因此,在这一点上,它试图找出“所需的”主机名是什么(通过主机头),然后看看你是否有一个:443虚拟主机的名字。如果不是,则将其交给默认:443虚拟主机。

0

假设

  • 您托管在同一httpd的实例的两个域
  • 你有口只有一个虚拟主机的定义443

林还假定当你说“作为父级重定向到子域”,这意味着只应在HTTPS子域(即https://sub.example.com)上显示的内容出现在HTTPS父域(即https://示例)上。 com loo ks完全像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> 

这样做不管你使用什么主机名的后果:

  • 对端口80的任何请求将始终产生父内容
  • 端口443的任何请求总是会产生子域内容

所以:

尝试增加“了NameVirtualHost *:443”(如果你不已经拥有它)和至少第三虚拟主机:

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 command具有-S标志,将输出的电流有序的虚拟主机的配置,然后退出,这是诊断什么当前虚拟主机上哪些端口定义和名称相关

-S 
    Show the settings as parsed from the config file (currently only shows the virtualhost settings). 

一些配置是有用的,版本和平台会对这个问题有所帮助。

0

的ServerAdmin网站管理员@本地

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