大网数据广告活动
服务器运维问答

Apache's virtualhost only for redirect

· 52CE 我爱测

I have multiple domains, but I have only one certificate. I have created two virtualhost's, one with certificate for domain: domain.lt second with redirects to domain.lt Apache's SSL config: <IfModule mod_ssl.c> <VirtualHost *:44…

问题原文

原帖链接 · Šarūnas Rakauskas · CC BY-SA 3.0

I have multiple domains, but I have only one certificate. I have created two virtualhost's, one with certificate for domain: domain.lt second with redirects to domain.lt

Apache's SSL config:

<IfModule mod_ssl.c>

    <VirtualHost *:443>
        <Directory "/var/www/html">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>

        ServerName domain.lt
        ServerAlias www.domain.lt     
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/domain.lt/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.lt/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        <Directory "/var/www/html/main/wp-content/uploads/">
            Options -Indexes
        </Directory>
    </VirtualHost>

    <VirtualHost *:443>
        <Directory "/var/www/html">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>

        ServerName domain.pk
        ServerAlias www.domain.pk
        ServerAlias domain.fi
        ServerAlias www.domain.fi
        ServerAlias domain.eu
        ServerAlias www.domain.eu
        ServerAlias domain.hk
        ServerAlias www.domain.hk
        ServerAlias domain.ae
        ServerAlias www.domain.ae

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

        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^(www.)?domain.(pk|fi|eu|hk|ae)$
        RewriteRule ^(.*)$ https://domain.lt%{REQUEST_URI} [L,R=301]
    </VirtualHost>

</IfModule>

But I'm still getting warnings in browser that the connection is not secure and the certificate is only for domain.lt. After adding exception in browser I'm being redirected. How can i accomplish that?

已采纳解答

原帖链接 · Daniel Widrick · CC BY-SA 3.0

The TLS(SSL) part of the connection happens before the HTTP part of the request.

This means that you MUST present a valid certificate for the domain the browser is requesting BEFORE you can send an HTTP 302/etc redirect. All of the HTTP winds up wrapped up in the TLS encryption.

Otherwise the end user browsers will show warnings that will need to be bypassed (not best practice).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。