惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
O
OpenAI News
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
有赞技术团队
有赞技术团队
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Hacker News: Ask HN
Hacker News: Ask HN
Help Net Security
Help Net Security
爱范儿
爱范儿
W
WeLiveSecurity
V2EX - 技术
V2EX - 技术
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
SecWiki News
SecWiki News
A
About on SuperTechFans
Cloudbric
Cloudbric
N
Netflix TechBlog - Medium
博客园 - 司徒正美
S
Security @ Cisco Blogs
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
I
InfoQ
Engineering at Meta
Engineering at Meta
Google Online Security Blog
Google Online Security Blog
T
Troy Hunt's Blog
Latest news
Latest news
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
B
Blog
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
V2EX
J
Java Code Geeks
N
News | PayPal Newsroom
T
Tor Project blog
The GitHub Blog
The GitHub Blog

博客园 - 过错

vscode的continue中配置第三方模型。以agnes-ai为例 在 Docker 容器中运行 .NET 6 并使用 libgdiplus(通常是为了支持 System.Drawing.Common 进行图片处理),你需要完成以下两个核心步骤 vs code调试netcore 为Ubuntu24生成netcore10的镜像, linux安装netcore nginx postgresql ssh 各种加速 不使用Debezium,记录PostgreSQL中的数据的数据前后变化 docker加速 python的一些设置 netcore 发布命令 一些代码库 The database cluster initialisation failed but was not the same version as initdb的解决办法(postgresql) NDVI计算 ,c#和python代码实现 使用c#调用chatgpt 。以下代码由ai自动生成。 vs Commit message的使用 Fiddler 替换资源 docker 部署 rabbitmq(持久化) 和postgresql redis mysql 油猴子常用脚本 通过nginx做身份验证网关的方法 ngnix 常用配置 Nginx配置之实现多台服务器负载均衡 Nginx配置优化详解
ngnix代理grpc
过错 · 2022-11-15 · via 博客园 - 过错

原文 http://www.1000zx.cn/it/13525.html

Nginx 1.13.10新增了对gRPC的原生支持。本文介绍如何配置Nginx的gRPC。

安装Nginx

Nginx版本要求:1.13.10。

gRPC必须使用HTTP/2传输数据,支持明文和TLS加密数据,支持流数据的交互。这是为了充分利用 HTTP/2 连接的多路复用和流式特性。所以在安装部署nginx时需要安装http/2。使用源码安装,编译时需要加入http_ssl和http_v2模块:

$ auto/configure --with-http_ssl_module --with-http_v2_module
Nginx以明文的方式发布gRPC服务。

nginx是使用http服务器监听gRPC的请求。

示例:

http {
server {
listen 80 http2;

access_log logs/access.log main;

location / {

The 'grpc://' prefix is optional; unencrypted gRPC is the default

grpc_pass grpc://localhost:50051;
}
}
}

指令grpc_pass用来指定代理的gRPC服务器地址,前缀协议有两种:

grpc://:与gRPC服务器端交互是以明文的方式
grpcs://:与gRPC服务器端交互式以TLS加密方式
gRPC服务器地址的前缀“grpc://”是可以忽略,默认就是明文交互方式。

此示例里nginx以明文的方式在80端口发布gRPC,其中代理的gRPC在后端也是以明文的方式交互。

注意:Nginx是不支持在明文的端口上同时支持http1和http2的。如果要支持这两种的http协议,需要设置为不同的端口。

Nginx以TLS加密方式公开gRPC服务

在生成环境建议使用Nginx是以加密的方式发布gRPC。这种情景需要在Nginx添加一个加密层。

在开发/测试环境可以使用自签名证书,关于自签名证书可以参考此简明教程。
配置示例:

server {
listen 1443 ssl http2;

ssl_certificate ssl/cert.pem;
ssl_certificate_key ssl/key.pem;

location / {
grpc_pass grpc://localhost:50051;
}
}

示例里在nginx层给gRPC服务对外添加了ssl,而内部代理到gRPC服务器仍然是使用明文的交互方式。

gRPC客户端也是需要TLS加密。如果是使用自签名证书等未经信任的证书,客户端都需要禁用证书检查。在部署到生产环境时,需要将自签名证书换成由可信任证书机构发布的证书,客户端也需要配置成信任该证书。

代理加密的gRPC

如果Nginx内部代理的gRPC也需要以加密的方式交互,这种情况就需要把明文代理协议grpc://替换为grpcs://。这首先要gRPC服务器是以加密的方式发布服务的。

nginx层修改如下:

grpc_pass grpcs://localhost:50051;
nginx路由gRPC请求

如果后端有多个gRPC服务端,其中每个服务端都是提供不同的gRPC服务。这种情况可以使用一个nginx接收客户端请求,然后根据不同的路径分发路由到指定的gRPC服务器。使用location区分:

location /helloworld.Greeter {
grpc_pass grpc://192.168.20.11:50051;
}

location /helloworld.Dispatcher {
grpc_pass grpc://192.168.20.21:50052;
}

location / {
root html;
index index.html index.htm;
}

对gRPC请求做负载均衡

在后端有多个gRPC服务器,它们都是同一个gRPC服务,这种情况可以结合nginx的upstream可以对gRPC的请求做负载均衡。

upstream grpcservers {
server 192.168.20.21:50051;
server 192.168.20.22:50052;
}

server {
listen 1443 ssl http2;

ssl_certificate ssl/certificate.pem;
ssl_certificate_key ssl/key.pem;

location /helloworld.Greeter {
grpc_pass grpc://grpcservers;
error_page 502 = /error502grpc;
}

location = /error502grpc {
internal;
default_type application/grpc;
add_header grpc-status 14;
add_header grpc-message "unavailable";
return 204;
}
}

其中upstream指定定义了统一gRPC服务的服务器组。在grpc_pass指定的gRPC服务器地址使用upstream定义的服务器组。