Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

deploy asp.net core web api to nginx 502 bad gateway

$
0
0

I created an empty asp.net core web api application and deploy it to nginx, it works well, but I tried to deploy my real project to nginx, it returns 502 bad gateway. Please check my files, anything wrong?

project.json

{"dependencies": {"Microsoft.ApplicationInsights.AspNetCore": "1.0.0","Microsoft.AspNetCore.Mvc": "1.0.0","Microsoft.AspNetCore.Server.IISIntegration": "1.0.0","Microsoft.AspNetCore.Server.Kestrel": "1.0.0","Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0","Microsoft.Extensions.Configuration.FileExtensions": "1.0.0","Microsoft.Extensions.Configuration.Json": "1.0.0","Microsoft.Extensions.Logging": "1.0.0","Microsoft.Extensions.Logging.Console": "1.0.0","Microsoft.Extensions.Logging.Debug": "1.0.0","Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0","log4net": "2.0.7","Newtonsoft.Json": "9.0.1","MySql.Data": "7.0.6-IR31","Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0","System.Net.Http": "4.1.0","System.Text.Encoding": "4.3.0","Microsoft.AspNetCore.Mvc.Core": "1.0.0","System.Net.Requests": "4.0.11","Microsoft.NETCore.App": "1.0.0"
  },"tools": {"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },"frameworks": {"netcoreapp1.0": {"imports": ["dotnet5.6","portable-net45+win8"
      ]
    }
  },"buildOptions": {"emitEntryPoint": true,"preserveCompilationContext": true
  },"runtimeOptions": {"configProperties": {"System.GC.Server": true
    }
  },"publishOptions": {"include": ["wwwroot","Views","Areas/**/Views","appsettings.json","web.config"
    ]
  },"scripts": {"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },"runtimes": {"win10-x64": {}
  }
}

The program file

 public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }

Startup file

public class Startup
    {
        public static ILog logger = log4net.LogManager.GetLogger(typeof(Startup));
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            log4net.Repository.ILoggerRepository repository = log4net.LogManager.CreateRepository("MyRepository");
            log4net.Config.XmlConfigurator.Configure(repository, new System.IO.FileInfo(env.ContentRootPath + "/App_Data/Configs/log4net.config"));
        }

        public IConfigurationRoot Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseMvc();
        }
    }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>