码迷,mamicode.com
首页 > Web开发 > 详细

Nginx系列(七)——HTTP/2

时间:2020-05-24 16:38:48      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:share   pack   index   cse   style   http   serve   grpc   location   

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;
}
}

Nginx系列(七)——HTTP/2

标签:share   pack   index   cse   style   http   serve   grpc   location   

原文地址:https://www.cnblogs.com/biaopei/p/12951323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!