2017-04-01 80 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