在一个 IP 上设置两个 https,两个域名也

在一个 IP 上设置两个 https,两个域名也

我有两个域名和一个 IP。两个域名都监听端口 80。端口 443 也监听其中一个域名(来自这两个)。但也有可能只通过 IP 访问其中一个域名。我屏蔽了端口 80 上的 IP,这样就没问题了。现在的问题是,使用 https(端口 443)和 IP,任何人都可以从其中一个域名访问页面。我如何将两个域名与 IP 访问分开?

domain1 listens on 80 only - this is ok
domain2 listens on 80 and 443 - this is ok
IP listens on 80 and 443 but must be blocked - don't know how to set it

为 443 设置了一个 VirtualHost,但尝试第二个 VirtualHost 不被 apache 接受。一切都在 Raspberry Pi (Raspbian) 上运行的 apache2 上设置。

编辑

我拥有的是:

ports.conf 文件:

ServerName localhost
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
    NameVirtualHost *:443
    ServerName 1st_domain.pl
    Listen 443
</IfModule>

ip.地址.文件:

<VirtualHost *:80>
    ServerName my.ip.address.here
    ServerAlias my.ip.address.here
    <Directory /*>
        Deny from all
    </Directory>
</VirtualHost>

1st_domain 文件:

<VirtualHost *:80>
    ServerName 1st_domain.pl
    ServerAlias www.1st_domain.pl
    ...
</VirtualHost>
<VirtualHost *:443>
    ServerName 1st_domain.pl
    ServerAlias www.1st_domain.pl
    ...
    SSLEngine on
    SSLCertificateFile ...crt
    SSLCertificateKeyFile ...key
</VirtualHost>

2nd_domain 文件:

<VirtualHost *:80>
    ServerName 2nd_domain.pl
    ServerAlias www.2nd_domain.pl
    ...
</VirtualHost>

答案1

如果您只希望通过 访问一个域HTTPS,请配置在端口 443 上监听的虚拟主机以仅处理该域。

我将使用的虚拟主机是:

  • 端口 80 上的域 1:可通过名称或 IP 地址访问(也处理所有无效域)
  • 端口 80 上的域 2:只能通过名称访问
  • 端口 443 上的域 2:响应所有 HTTPS 请求

您可以在端口 443 上使用默认域,并使用您正在服务的域的 SSL 密钥来捕获其他域的请求。(如果您想在一个 IP 上托管多个 HTTPS 域,您可以在证书上使用别名。我还没有设法使证书协商正常工作。)

如果您不想响应没有Host标头的请求,请创建一个默认虚拟主机并使其拒绝所有请求。这可以通过 modRewrite 来实现,或者通过将域置于服务器无法读取的目录中来实现。

答案2

如果看不到您的具体配置就很难解释,但是;

看一下http://httpd.apache.org/docs/2.2/vhosts/examples.html这解释得很好。

# Ensure that Apache listens on port 80
Listen 80
Listen 443

<VirtualHost *:443>
DocumentRoot /www/example1
ServerName www.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

相关内容