I have several virtual hosts on nginx
.
Can I enable HTTP/2
for specific virtual hosts only on nginx
?
When I enable HTTP/2
for a virtual host, like:
server {
listen 443 ssl http2;
server_name a.b.com;
...
}
I can access a.b.com by HTTP2.0.
But now every other virtual host on the same nginx
supports HTTP/2 too.
But I want to access them only by HTTP/1.1
.
Is the http2
directive at server level?
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.
In your case, there's only one process that handles all the virtual hosts bound to *:443
, so the process includes the http2
capability.
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.
For the virtual hosts you want to be accessed via http2
, you must either:
listen 8443 ssl http2;
) and remove http2
from all the others
(e.g. `listen 443 ssl;)listen new_ip:443 ssl http2;
and listen current_ip:443 ssl;
respectively)Example config for multiple IPs:
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;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With