Nginx系列(七)——HTTP/2

HTTP/2
Basic Configuration
server {
listen 443 ssl http2 default_server; #添加http2参数
ssl_certificate server.crt;
ssl_certificate_key server.key;
...
}

gRPC
不对HTTP/2进行加密
server {
listen 80 http2;
location / {
grpc_pass grpc://backend.local:50051;
}
}
使用TLS加密,开启SSL和HTTP/2
server {
listen 443 ssl http2 default_server;
ssl_certificate server.crt;
ssl_certificate_key server.key;
location / {
grpc_pass grpc://backend.local:50051;
}
}
分别对gRPC和non-gRPC响应
location /mypackage.service1 {
grpc_pass grpc://backend.local:50051;
}
location /mypackage.service2 {
grpc_pass grpc://backend.local:50052;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
对gRPC进行负载均衡
upstream grpcservers {
server backend1.local:50051;
server backend2.local:50051;
}
server {
listen 443 ssl http2 default_server;
ssl_certificate server.crt;
ssl_certificate_key server.key;
location / {
grpc_pass grpc://grpcservers;
}
}


HTTP/2 Server Push
主动推送内容到client
server {
listen 443 ssl http2 default_server;
ssl_certificate server.crt;
ssl_certificate_key server.key;
root /usr/share/nginx/html;
location = /demo.html {
http2_push /style.css; #推送URL的路径
http2_push /image1.jpg;
}
}

posted on 2020-05-24 16:11  标配的小号  阅读(387)  评论(0编辑  收藏  举报

导航