【发布时间】:2020-01-03 12:29:44
【问题描述】:
架构图显示了我如何在 AWS 上设置应用程序。
如果 Application Server 组和 Web Server 组位于公共子网中,则一切正常。但是,当我将应用服务器放在私有子网中时,所有 API 调用都会超时,因为这些子网没有连接 Internet 网关。
我希望 Nodejs 应用程序服务器仍然在私有子网中,而 nginx Web 服务器在公共子网中。 Web 服务器组的应用程序负载均衡器面向互联网,但应用程序服务器组的应用程序负载均衡器是内部的,而不是面向互联网的。
是否有可能使该架构正常工作,同时仍将应用服务器保留在私有子网中?
Nginx 设置如下。
server {
listen 80;
listen [::]:80;
server_name www.example.com;
proxy_set_header X-Forwarded-Proto $scheme;
if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://$host$request_uri;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass https://api.example.com;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 443;
listen [::]:443;
server_name example.com;
location / {
proxy_pass http://api.example.com;
root /usr/share/nginx/html;
index index.html index.htm;
}
}
53 号公路
记录设置
www.example.com A -- 面向负载平衡器 DNS 的网络服务器互联网
api.example.com A -- 应用服务器内部负载均衡器 DNS
NACL 设置
为每个子网设置一个 NACL。
入境
出站
Web 负载均衡器安全组允许端口 80 和 443 上的所有流量 Web 服务器安全组允许来自 Web 负载均衡器安全组的端口 80 和 443 上的所有流量 内部负载均衡器安全组来自 Web 服务器安全组的端口 80 和 443 以及来自应用服务器安全组的端口 3000 上的所有流量 应用服务器安全组允许端口 3000 上的流量从 Internal Load Balancer 安全组、27017 到 MongoDB Atlas VPC 对等连接、HTTPS 到 S3 的 VPC Gateway Enpoint、6379 到 redis 安全组。
有没有办法可以将应用服务器保留在私有子网中,并且在对 api.example.com/abc 端点进行任何调用时都不会出现此连接超时问题?
提前感谢您的帮助。
【问题讨论】:
标签: node.js amazon-web-services nginx amazon-ec2 aws-security-group