[英]Can I enable HTTP/2 for specific server blocks (virtual hosts) only, on Nginx?
I have several virtual hosts on nginx
. 我在
nginx
上有几个虚拟主机。
Can I enable HTTP/2
for specific virtual hosts only on nginx
? 我是否可以仅在
nginx
上为特定虚拟主机启用HTTP/2
?
When I enable HTTP/2
for a virtual host, like: 当我为虚拟主机启用
HTTP/2
,例如:
server {
listen 443 ssl http2;
server_name a.b.com;
...
}
I can access abcom by HTTP2.0. 我可以通过HTTP2.0访问abcom。
But now every other virtual host on the same nginx
supports HTTP/2 too. 但是现在同一个
nginx
上的每个其他虚拟主机也支持HTTP / 2。 But I want to access them only by HTTP/1.1
. 但我想只通过
HTTP/1.1
访问它们。
Is the http2
directive at server level? http2
指令是否在服务器级别?
Short answer: not possible on your current setup. 简短回答:目前的设置无法实现。
When starting, nginx
first creates a separate process for every group of virtual hosts that listen on the same IP:port combination, and then sets the capabilities of that process to be the sum of all capabilities of every virtual host in that group handled by said process. 启动时,
nginx
首先为侦听同一IP:端口组合的每组虚拟主机创建一个单独的进程,然后将该进程的功能设置为该组处理的该组中每个虚拟主机的所有功能的总和。处理。
In your case, there's only one process that handles all the virtual hosts bound to *:443
, so the process includes the http2
capability. 在您的情况下,只有一个进程处理绑定到
*:443
所有虚拟主机,因此该进程包括http2
功能。
In order to achieve what you want, you need to make nginx
spawn a different process that doesn't have the http2
capability on a separate IP:port combination. 为了实现您想要的,您需要使
nginx
生成一个不同的进程,该http2
在单独的IP:端口组合上没有http2
功能。
For the virtual hosts you want to be accessed via http2
, you must either: 对于要通过
http2
访问的虚拟主机,您必须:
listen 8443 ssl http2;
) and remove http2
from all the others (eg `listen 443 ssl;) listen 8443 ssl http2;
)并从所有其他端口中移除http2
(例如`listen 443 ssl;) listen new_ip:443 ssl http2;
and listen current_ip:443 ssl;
respectively) listen new_ip:443 ssl http2;
并分别listen current_ip:443 ssl;
) Example config for multiple IPs: 多个IP的配置示例:
server {
listen current_ip:443 ssl;
server_name http11-host.example.com;
...
}
server {
listen current_ip:443 ssl;
server_name another-http11-host.example.com;
...
}
...
...
server {
listen new_ip:443 ssl http2;
server_name http2-host.example.net;
...
}
server {
listen current_ip:443 ssl http2;
server_name another-http2-host.example.org;
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.