简体   繁体   中英

How Run ASP.NET Core port other than 5000 on Ubuntu?

I have been using supervisor on ubuntu since dotnet 2 and have had no issues. Since my upgrade to dotnet version 3.1 I am getting an error saying port 5000 is in use when my supervisor file has always been configured to use 5001.

[program:myapi]]
command=/usr/bin/dotnet /var/www/api/api.dll --server.urls "http://*:5001"
directory=/var/www/api/
autostart=true
autorestart=true
stderr_logfile=/var/log/api.err.log
stdout_logfile=/var/log/api.out.log
environment=ASPNETCORE_ENVIRONMENT=Development
user=www-data
stopsignal=INT

I have another app running on 5000 which works fine but can't figure why after upgrading to 3.1 the port is defaulted to 5000 even when configured to use 5001.

Program.cs is pretty standard

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });
}

You need to change port in LaunchSettings.json file.

 "{Your Project Name}": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "{http/https}://localhost:{Port No You want to change}/"
    },

or in program.cs use following code

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .UseUrls("{https/http}://localhost:{Port No You want to change}/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM