2

如前所述,我在我的 apache 日志中收到以下错误消息。

[Sat Jun 22 12:57:53.746190 2019] [proxy:error] [pid 10299:tid 140435221571328] (111)Connection refused: AH00957: HTTPS: attempt to connect to 127.0.0.1:5001 (127.0.0.1) failed
[Sat Jun 22 12:57:53.746228 2019] [proxy:error] [pid 10299:tid 140435221571328] AH00959: ap_proxy_connect_backend disabling worker for (127.0.0.1) for 60s
[Sat Jun 22 12:57:53.746233 2019] [proxy_http:error] [pid 10299:tid 140435221571328] [client myip:65168] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

使用代码管道进行部署时,我看不到任何错误消息。

我已经尝试了以下所有方法;

  • 重新启动并重建我的应用程序。
  • 调整我的 ASP 项目中的 launchSettings.json 文件。
  • 在我的 Program 类中调整端口并启用/禁用 HTTPS 重定向。
  • 在 apache 中调整我的 vhsosts 文件。

这里有一些重要的文件供您浏览;

启动设置.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44335",
      "sslPort": 44335
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_My_Environment": "1",
        "ASPNETCORE_DETAILEDERRORS": "1",
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ProjectName": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    }
  }
}

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass "/" "http://127.0.0.1:5000/"
    ProxyPassReverse "/" "http://127.0.0.1:5000/"
</VirtualHost>

/etc/apache2/sites-enabled/000-default-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine on

    ProxyPreserveHost On
    ProxyPass "/" "https://127.0.0.1:5001/"
    ProxyPassReverse "/" "https://127.0.0.1:5001/"
    ServerName mydomain.com
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
</VirtualHost>
</IfModule>

启动.cs

        public void ConfigureServices(IServiceCollection services)
        {
            var logger = _loggerFactory.CreateLogger<Startup>();


            logger.LogInformation($"Environment: {_env.EnvironmentName}");

            // Development service configuration
            if (_env.IsDevelopment())
            {
                logger.LogInformation("Development environment");

                services.Configure<ForwardedHeadersOptions>(options =>
                {
                    options.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));
                });

                services.AddHttpsRedirection(options =>
                {
                    options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
                    options.HttpsPort = 44335;
                });
            }

            // Live Service Config
            if (!_env.IsDevelopment())
            {
                services.AddHttpsRedirection(options =>
                {
                    options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect;
                    options.HttpsPort = 5001;
                });

                services.Configure<ForwardedHeadersOptions>(options =>
                {
                    options.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));
                });

                services.AddHsts(options =>
                {
                    options.Preload = true;
                    options.IncludeSubDomains = true;
                    options.MaxAge = TimeSpan.FromDays(60);
                });

            }

            //lines removed for berevity.
}
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Dev Envoronments
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseHttpsRedirection();
            }

            if (env.IsProduction())
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();

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


            app.UseHttpsRedirection();
            //lines removed for berevity.
}

如果您需要更多信息,请告诉我。

编辑:服务器:EC2 Ubuntu(通过 Code Star 构建),Web 服务:Apache,项目代码:asp.net core 2.1,SSL 证书:LetsEncrypt,代理:不是 100% 确定。

4

1 回答 1

3

尝试以下代码,使 HTTPD 脚本和模块能够连接到网络。

/usr/sbin/setsebool -P httpd_can_network_connect 1
于 2020-08-19T21:11:17.243 回答