我有 2 个实例,一个用于后端(URL:be.domain.com),另一个用于前端(URL:fe.domain.com),分别通过 Backend-TG 和 frontend-TG 指向。AWS 应用程序负载均衡器用于根据主机标头配置规则。
ALB 侦听器规则为 80 和 443,所有 HTTP 请求在 alb 中均被强制为 https,并且在负载均衡器上使用来自 ACM 的 SSL。
我的 Nginx 配置文件为 backend.conf:
server {
server_name be.domain.com;
listen 80;
location /dashboard/ {
include proxy_params;
proxy_pass http://127.0.0.1:5050;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /apipath/ {
include proxy_params;
proxy_pass http://127.0.0.1:5050;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Nginx conf 的 frontend.conf:\
server {
server_name fe.domain.com;
listen 80;
location /apipath/ {
include proxy_params;
proxy_pass https://be.domain.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /dashboard/ {
include proxy_params;
proxy_pass https://be.domain.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location / {
## Your only path reference.
root /var/www/code;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
我已经使用 cname 通过 alb DNS 创建了域别名。
前端是 angular 代码和 fe.domain.com 代理,将 API 调用传递到后端。现在我面临 API 通信中 502 状态错误的问题?
任何帮助都将不胜感激。我感觉存在一些代理传递问题。有人可以指导我吗?