【问题标题】:502 Bad Gateway nginx/1.14.1 elasticbeanstalk .net core app running on docker502 Bad Gateway nginx/1.14.1 elasticbeanstalk .net core app 在 docker 上运行
【发布时间】:2019-11-25 03:02:42
【问题描述】:

我在 docker 中运行 .net 核心应用程序,当我将映像部署到亚马逊 Elastic Beanstalk 时,状态正常,但是当我尝试访问该页面时,我得到“502 Bad Gateway nginx/1.14.1”

Docker 文件:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR  /src
COPY ["MyApp.csproj", "."]
RUN dotnet restore "MyApp.csproj"
COPY . .
RUN dotnet build "MyApp.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app

FROM base AS final
WORKDIR . /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Dockerrun.aws.json

{
"AWSEBDockerrunVersion": "1",
  "Image": {
"Name": "xxxx/myapp",
"Update": "true"
},
"Ports": [
{
  "ContainerPort": "80"
}
 ]
}

日志:

2019/07/16 10:55:34 [error] 13553#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.32.153.2, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.3:80/", host: "myapp-env11.us-east-1.elasticbeanstalk.com"

我应该打开哪个端口才能运行它?

【问题讨论】:

  • 在同样的事情上挣扎。有没有想过这个?
  • 所以没有人想到这一点? @kaszanka 你是怎么解决这个问题的?

标签: c# docker amazon-ec2 .net-core amazon-elastic-beanstalk


【解决方案1】:

所以我今天早些时候遇到了同样的问题。事实证明这是我的应用程序无法启动的问题,所以 nginx 无法访问它。

在查看日志之后。我发现这是一个连接字符串问题,因为我的应用程序是在本地启动的,当我部署到 IIS 时,而不是在部署到 AWS elastic-beanstalk 时。

我的应用程序不是 dockerized 应用程序,但同样的问题几乎让我度过了糟糕的一天。

所以,我的建议是,下载您的日志并查看日志中是否存在任何特定于应用程序的错误,在我的情况下,我必须检查 web.stdout 日志。

所以我修复了我的连接字符串问题。

发件人:

"DefaultConnection": "Server=dbserverURL,1433;Database=DbName;User Id=dbuser;Password=dbPass;Trusted_Connection=True;MultipleActiveResultSets=true"

收件人:

"DefaultConnection": "Server=dbserverURL,1433;Database=DbName;Integrated Security=false;User Id=dbuser;Password=dbPass;MultipleActiveResultSets=true"

【讨论】:

    猜你喜欢
    • 2017-04-18
    • 2021-12-19
    • 2019-06-14
    • 2015-06-29
    • 2017-12-12
    • 2020-08-01
    • 2018-09-12
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多