在项目上本来一直使用的是http协议,后来因为安全和一些其他原因需要上https协议,如果发布项目之后想同时兼容http和https协议需要更改一下配置信息,下面一起看一下:
首先你需要先申请一张服务器证书,申请后将证书安装到服务器上(也可以在iis中选择服务器证书导入)。
添加Urls节点:节点中配置http端口和https端口
App节点中的地址默认为localhost就可以
{
"App": {
"SelfUrl": "http://localhost:44386",
"CorsOrigins": "https://*.aaa.com,http://localhost:4200,https://localhost:44307,http://localhost:8080,http://192.168.0.86:8080",
"RedirectAllowedUrls": "http://localhost:4200,https://localhost:44307"
},
"ConnectionStrings": {
"Default": "Server=111.111.11.11; Database=Test; Persist Security Info=True;User ID=sa;Password=123;Packet Size=512;"
},
"Redis": {
"RedisConnectionString": "111.111.11.11:6379,password=12312312313,ConnectTimeout=15000,SyncTimeout=5000"
},
"AuthServer": {
"Authority": "http://localhost:44386",
"RequireHttpsMetadata": "false",
"SwaggerClientId": "Test_Swagger",
"SwaggerClientSecret": "1123"
},
"StringEncryption": {
"DefaultPassPhrase": "paaaaaaa"
},
"Urls": {
"Http": {
"Host": "localhost",
"Port": 44386
},
"Https": {
"Host": "localhost",
"Port": 447
}
},
"Settings": {
"Abp.Mailing.Smtp.Host": "127.0.0.1",
"Abp.Mailing.Smtp.Port": "25",
"Abp.Mailing.Smtp.UserName": "",
"Abp.Mailing.Smtp.Password": "",
"Abp.Mailing.Smtp.Domain": "",
"Abp.Mailing.Smtp.EnableSsl": "false",
"Abp.Mailing.Smtp.UseDefaultCredentials": "true",
"Abp.Mailing.DefaultFromAddress": "[email protected]",
"Abp.Mailing.DefaultFromDisplayName": "ABP application",
"Abp.Identity.Lockout.MaxFailedAccessAttempts": 20,
"Abp.Identity.Lockout.LockoutDuration": 180,
//"Abp.Identity.Password.RequiredUniqueChars": false,
"Abp.Identity.Password.RequireNonAlphanumeric": false,
//"Abp.Identity.Password.RequireLowercase": false,
"Abp.Identity.Password.RequireUppercase": false,
"Abp.Identity.Password.RequireDigit": false
}
}
把http和https的地址和端口配置到webBuilder.UseUrls(“http://localhost:44386”, “https://localhost:447”).UseStartup(); 中
internal static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("http://localhost:44386", "https://localhost:447").UseStartup<Startup>();
})
.UseAutofac()
.UseSerilog();
在绑定https协议时SSL证书需要选择第一步导入的证书