.net core 3.1 Linux部署

由 jafucong 发布

1. 更换 监听端口和域名

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseUrls("http://*:17080");

2. 自启动

创建自启动文件
nano /etc/systemd/system/CrmCommServer.service

[Unit]
Description=CommServer

[Service]
WorkingDirectory=/www/wwwroot/CommServer/
ExecStart=dotnet /www/wwwroot/CommServer/CommServer.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-CommServer
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

使自启动生效
systemctl enable CrmCommServer.service
立即启动服务
systemctl start CrmCommServer.service
查看服务状态
systemctl status CrmCommServer.service

3. https支持

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHttpsRedirection(); //仅支持https 去掉后支持HTTP和https都支持
            app.UseMvc();
        }
public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseKestrel(J=> 
                {
                    J.ListenAnyIP(17080);
                    J.ListenAnyIP(443,K=> 
                    {
                        K.UseHttps(@"E:\SVN\EliteCRM\2.8.5\安装包\openssl.pfx", "XXXXXX");
                    });
                });
    }

暂无评论

发表评论