title: How to run asp.net core 2.1 release app at a specific port?
body: <p>Environment: ASP.NET Core 2.1 under Ubuntu 18.04</p>
  
  <p>By default, a newly created asp.net core app runs at <a href="http://localhost:5000" rel="noreferrer">http://localhost:5000</a> and automatically redirects to <a href="https://localhost:5001" rel="noreferrer">https://localhost:5001</a></p>
  
  <p>As I intend to run my app under nginx (and use SSL capabilities of nginx), I would like to run my released app without https and at a specific port, say, 6000.</p>
  
  <p>Post <a href="https://stackoverflow.com/questions/50935730/asp-net-core-2-1-kestrel-how-to-disable-https">ASP.NET Core 2.1 + Kestrel (How to disable HTTPS)</a> explains that one has to simply use "--urls" argument to achieve this.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>$ dotnet publish --configuration Release
  $ dotnet bin/Release/netcoreapp2.1/MyApp.dll
  </code></pre>
  
  <p>The app now starts listening at <a href="http://localhost:5000" rel="noreferrer">http://localhost:5000</a> and <a href="https://localhost:5001" rel="noreferrer">https://localhost:5001</a>. When I browse to <a href="http://localhost:5000" rel="noreferrer">http://localhost:5000</a>, it automatically redirects to <a href="https://localhost:5001" rel="noreferrer">https://localhost:5001</a>. So far so good.</p>
  
  <p>Now, I try running at port 6000:</p>
  
  <pre><code>$ dotnet bin/Release/netcoreapp2.1/MyApp.dll
       --urls="http://localhost:6000"
  </code></pre>
  
  <p>From the messages in the terminal window, the app seems to start listening at <a href="http://localhost:6000" rel="noreferrer">http://localhost:6000</a>. However, browsing to this url results in "this site can't be reached" error.</p>
  
  <p>I even tried:</p>
  
  <pre><code>$ dotnet bin/Release/netcoreapp2.1/MyApp.dll
       --urls="http://localhost:6000,https://localhost:6001"
  </code></pre>
  
  <p>In this case, I get an error that "a path base can only be configured using IApplicationBuilder.UsePathBase()."</p>
  
  <p>Can someone please tell me how I can simply run an application at a specified port? I am hoping I don't need to hard-code port numbers.</p>