【发布时间】:2022-10-02 00:27:15
【问题描述】:
我在 nginx 中安装了一个 react 应用程序,然后是一个 express.js 服务器,用于连接到 mysql 的后端。当客户端向 x.com/ 请求时,来自 nginx 的 default.conf 指示从本地 /var/www/build 文件夹中选择文件,当路径为 x.com/api 时,nginx 会将调用重定向到express.js 服务器。
upstream client {
server client:3000;
}
upstream api {
server api:3001;
}
server {
listen 80;
#location / {
# proxy_pass http://client;
#}
location / {
root /var/www/build;
try_files $uri /index.html;
}
# location /sockjs-node {
# proxy_pass http://client;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection \"Upgrade\";
# }
location /sockjs-node {
root /var/www/build;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection \"Upgrade\";
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
}
}
我的问题是,现在我将所有内容都放入容器和 K8s 集群中,我使用了 Istio 网关。但在我的配置中,只是通过网关中的所有流量到 nginx 容器。
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: rproxygw
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- \"*\"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rproxy
spec:
hosts:
- \"*\"
gateways:
- rproxygw
http:
- match:
- uri:
prefix: /
route:
- destination:
host: rproxy
port:
number: 80
既然一切都在使用 Istio 的 K8s 集群上,那还有什么更好的呢?只是从网关重定向 x.com/api?
有没有办法将 react 静态文件安装到 Istio 网关并摆脱 nginx 代理?
如何摆脱 nginx 作为反向代理,只使用 Istio 网关并将 react 应用程序安装到另一个 express 服务器中,或者只是重用运行后端的 express 服务器来安装 react 静态文件?
哪个选项在延迟方面表现最好?
标签: reactjs nginx kubernetes istio