使用 Elastic Beanstalk 为在 AWS Linux 2 上运行的 .NET 应用程序配置 nginx 代理

问题描述 投票:0回答:0

我在一家小型科技初创公司工作,我们有一个微服务 .NET 应用程序,它使用 Microsoft Identity Server 托管在 AWS Elastic Beanstalk 中运行在 Windows 服务器上。我们希望将我们的服务器迁移到 AWS Linux 2,并且已经成功部署了一项在 AWS Linux 2 上运行的 API 服务,没有任何问题。

我现在正试图让我们的一个前端 Web 服务器部署到一个新的 AWS Linux 2 Elastic Beanstalk 应用程序并且一直遇到问题。

我们使用在 AWS 中运行的 Microsoft Identity Server(目前在 Windows 服务器上)。通过查看日志和阅读大量站点,我发现,由于登录请求到达我们的身份服务器时 nginx 代理服务器的工作方式,它不再来自 https。这让我发现了这篇文章:https://serverfault.com/questions/917511/nginx-proxy-to-aws-elb-not-passing-https-protocol-to-backend-instances。看来解决方案与将此行添加到 nginx.conf 相关:

proxy_set_header X-Forwarded-Ssl on;

我们没有手动安装或配置nginx,而是我们只是在Elastic Beanstalk 配置中选择了这个选项作为代理服务器。 enter image description here

这篇 AWS 文档文章提供了有关将配置文件放在我们的源代码中的何处以部署附加内容或我们自己的 nginx.conf 的说明,但没有给出文件应该是什么样子或需要是什么样子的示例,因为我我不确定添加到基础 Elastic Beanstalk nginx.conf 的位置:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html

我在这篇文章中看到(在我们需要使用的运行 HTTPS 的应用程序中,重定向 URI 作为 HTTP 而不是 HTTPS 发送

ForwardedHeadersOptions forwardedHeadersOptions = new ForwardedHeadersOptions()
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                };

                forwardedHeadersOptions.KnownNetworks.Clear();
                forwardedHeadersOptions.KnownProxies.Clear();

                app.UseForwardedHeaders(forwardedHeadersOptions);

但是,我现在不确定如何正确配置 nginx 以在 conf 中将 HTTP 重定向到 HTTPS,也不确定该配置需要驻留在源代码中的哪个级别。

我试过放这个文件

location / {

    proxy_set_header X-Forwarded-Proto $scheme;
}

在我的源代码中的这条路径中:/.platform/nginx/config.d/https.conf

但这一直没有成功。非常感谢任何人可以提供的帮助!

.net amazon-web-services nginx amazon-elastic-beanstalk asp.net-identity
© www.soinside.com 2019 - 2024. All rights reserved.