title: Nginx reverse proxy re-direct to Account/Login
body: <p>The redirection to the standard MVC "Login" page does not work.</p>
  
  <p>I develop under Windows using Visual Studio 2017 - This a a standard templated Asp.Net Core 2.0 MVC package.</p>
  
  <p>All works well locally under Windows.</p>
  
  <p>However when I publish to a Ubuntu 16.04-x64 box, the redirection fails.</p>
  
  <p>I have Nginx providing reverse proxy as follows:</p>
  
  <p><code>server {
      listen 24147;
      location / {
          proxy_pass http://localhost:5001;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
      }
  }</code></p>
  
  <p>And in my Startup.cs:</p>
  
  <p><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      var forwardedHeadersOptions = new ForwardedHeadersOptions
      {
          ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
          // ForwardedHeaders = ForwardedHeaders.All  (also tried)
      };
      forwardedHeadersOptions.KnownNetworks.Clear();   // Tried both with and
      forwardedHeadersOptions.KnownProxies.Clear();    // without these lines
      app.UseForwardedHeaders(forwardedHeadersOptions);
      // .....
      app.UseAuthentication();
      // .....
  }</code></p>
  
  <p>Program.cs:</p>
  
  <p><code>public static IWebHost BuildWebHost(string[] args)
  {
      return WebHost.CreateDefaultBuilder(args)
          .UseStartup()
          .UseUrls("<a href="http://localhost:5001" rel="nofollow noreferrer">http://localhost:5001</a>")
          .Build();
  }</code></p>
  
  <p>All hyper-links within the web page are correct eg:  <code>"myserver.com:24147/Home/Online"</code>, but the redirection when attempting to access a page that requires authorisation gets a "404 Not Found".</p>
  
  <p>Under Ubuntu the redirect address used is <code>"myserver.com/Account/Login?ReturnUrl=%2FHome%2FOnline"</code>  (Note the missing port number)</p>
  
  <p>Under Windows the address used is <code>"localhost:5001/Account/Login?ReturnUrl=%2FHome%2FOnline"</code> (correct, with port number)</p>
  
  <p>I have scoured Google and StackOverflow for solutions and tried all configurations put forward - all to no avail.</p>
  
  <p>Any help greatly appreciated. </p>