zoukankan      html  css  js  c++  java
  • ASP .Net Core 2.0 修改默认端口

    ASP .Net Core 的默认端口是5000,如果想在同一台服务器上运行多个实例,就不能都监听5000端口了,需要每一个实例都监听不同的端口。当然,如果您正在使用IIS或者Jexus来托管,可以不用特意修改端口即可正常运行多个实例。

    方式一

    第一种方式是直接修改修改程序,在初始化Kestrel Server的时候指定端口:

    namespace ZKEACMS.WebHost
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                var host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .UseStartup()
                    .UseUrls("http://*:5123") //直接指定端口
                    .Build();
    
                host.Run();
            }
        }
    }

    直接写死在程序里的这种做法显然不是推荐的,不方便使用。

    方式二

    可以通过设置环境变量(ASPNETCORE_URLS)的方式来修改.Net Core的默认端口(5000)。

    开发环境

    # Unix:
    ASPNETCORE_URLS="http://*:5123" dotnet run
    
    # Windows PowerShell:
    $env:ASPNETCORE_URLS="http://*:5123" ; dotnet run
    
    # Windows CMD (note: no quotes):
    SET ASPNETCORE_URLS=http://*:5123 && dotnet run

    Visual Studio

    生产环境

    # Unix:
    ASPNETCORE_URLS="http://*:5123" dotnet application.dll
    
    # Windows PowerShell:
    $env:ASPNETCORE_URLS="http://*:5123" ; dotnet application.dll
    
    # Windows CMD (note: no quotes):
    SET ASPNETCORE_URLS=http://*:5123 && dotnet application.dll

    Linux的Unit配置

    增加一个Environment配置即可。Environment=ASPNETCORE_URLS=http://*:5123

    [Unit]
    Description=ZKEACMS
    
    [Service]
    WorkingDirectory=/root/cms
    ExecStart=/usr/bin/dotnet /root/cms/ZKEACMS.WebHost.dll
    Restart=always
    RestartSec=10
    SyslogIdentifier=zkeacms
    User=root
    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=ASPNETCORE_URLS=http://*:5123
    
    [Install]
    WantedBy=multi-user.target

    原文地址:http://www.zkea.net/codesnippet/detail/post-83

  • 相关阅读:
    ip聚合(百度之星资格赛1003)
    encoding(hdoj1020)
    Candy Sharing Game(hdoj1034)
    you can Solve a Geometry Problem too(hdoj1086)
    Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂
    Computer Transformation(hdoj 1041)
    Digital Roots(hdoj1013)
    humble number(hd1058)
    FatMouse' Trade(hdoj1009)
    1021 Fibonacci Again (hdoj)
  • 原文地址:https://www.cnblogs.com/seriawei/p/8303351.html
Copyright © 2011-2022 走看看