在同一服务器上使用不同端口设置多个 https

在同一服务器上使用不同端口设置多个 https

我正在尝试通过 apache 或 nginx 虚拟主机设置多个 https 网站,但我注意到我必须将端口附加到 IP 地址的末尾才能查看使用非默认 443 ssl 端口的网站的 https

同一台服务器上可以使用不同端口的多个 https 网站是否可行?如果可以,那么如何才能做到这一点而不需要在末尾附加非默认端口

我已尝试过

# Ensure that Apache listens on port 80 and all ssl ports
Listen 80 
Listen 443
Listen 543


# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
NameVirtualHost *:443
NameVirtualHost *:543

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

# Other directives here

</VirtualHost>

<VirtualHost 192.168.101.54:543>
DocumentRoot /www/example2
ServerName www.example2.org

# Other directives here

</VirtualHost>

按此顺序,将能够访问https://www.example1.comhttps://www.example2.org分别

这可能吗?Apache?Nginx?我使用这两种网络服务器,所以想知道它是否可以与其中一种或两种服务器一起使用。如果需要,我可以编辑问题以使其更清晰。

谢谢

答案1

您可以在一台服务器上使用一个 IP 地址为任意数量的站点提供服务,并且每个域都可以监听端口 80 和 443。因此,example.com 可以监听 80/443,example1.com 可以监听 80/443,等等。

在 nginx 中,你只需定义多个服务器,如下所示

server {
  server_name www.example.com;
  listen 80;
  listen 12345;
  listen 443 ssl;

  location / {
    # whatever
  }
}

server {
  server_name www.example1.com;
  listen 80;
  listen 443 ssl;

  location / {
    # whatever
  }
}

# This server simply redirects the requested to the https version of the page
server {
  listen 80;
  server_name example.com;
  return 301 https://www.example.com$request_uri;
}

您最好将 80 转发到 443,这样一切都会安全。我有一套非常详尽的配置文件本教程,以及大量关于 nginx 的一般内容。

注意,有人建议直接编辑我教程的另一部分。我直接链接到该页面,因为该页面包含整个系列教程的目录,以及您可以下载的 nginx 配置文件。

答案2

是否可以在同一服务器上使用不同的端口建立多个 https 网站?

是的,基于名称的虚拟主机是该技术的广义名称。旧金山和整个互联网上都有很多这种例子。

如果是,那么如何才能做到这一点而不需要在末尾附加非默认端口

不能。标准为 HTTP 定义了端口 80,为 HTTPS 定义了端口 443,因此您无需提供它们,并且您的标准兼容工具会根据方案知道在哪里连接。

如果您使用非标准端口,那么您必须提供它。

相关内容