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=
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
ASP .Net Core 2.0 修改默认端口的更多相关文章
- 升级 ASP.NET Core 3.0 设置 JSON 返回 PascalCase 格式与 SignalR 问题
由于一些 JS 组件要求 JSON 格式是 PascalCase 格式,新版本 ASP.NET Core 3.0 中默认移除了 Newtonsoft.Json ,使用了微软自己实现的 System.T ...
- 探索 ASP.Net Core 3.0系列五:引入IHostLifetime并弄清Generic Host启动交互
前言:在本文中,我将介绍如何在通用主机之上重新构建ASP.NET Core 3.0,以及由此带来的一些好处. 同时也展示了3.0中引入新的抽象类IHostLifetime,并描述了它在管理应用程序(尤 ...
- ASP.net core 2.0.0 中 asp.net identity 2.0.0 的基本使用(一)—修改数据库连接
开发环境:vs2017 版本:15.3.5 项目环境:.net framework 4.6.1 模板asp.net core 2.0 Web应用程序(模型视图控制器) 身份验证:个人用户账号 ...
- 跨平台运行ASP.NET Core 1.0
前言 首先提一下微软更名后的叫法: ASP.NET 5 更名为 ASP.NET Core 1.0 .NET Core 更名为 .NET Core 1.0 Entity Framework 7 更名为 ...
- 将 ASP.NET Core 1.0 应用作为 docker 镜像发布 (Linux版)
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- ASP.NET Core 1.0 入门——了解一个空项目
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- 跨平台运行ASP.NET Core 1.0(转载)
前言 首先提一下微软更名后的叫法: ASP.NET 5 更名为 ASP.NET Core 1.0 .NET Core 更名为 .NET Core 1.0 Entity Framework 7 更名为 ...
- Amazing ASP.NET Core 2.0
前言 ASP.NET Core 的变化和发展速度是飞快的,当你发现你还没有掌握 ASP.NET Core 1.0 的时候, 2.0 已经快要发布了,目前 2.0 处于 Preview 1 版本,意味着 ...
- ASP.NET Core 2.0 新功能汇总
前言 ASP.NET Core 的变化和发展速度是飞快的,当你发现你还没有掌握 ASP.NET Core 1.0 的时候, 2.0 已经快要发布了,目前 2.0 处于 Preview 1 版本,意味着 ...
随机推荐
- 易捷框架之EChart 的使用
需要用到百度的报表控件 ,总结如下: 1,先引入开发包,以及主题包: <%@ include file="./common/echarts_header.jsp"%> ...
- input 隐藏边框
style='border-left:0px;border-top:0px;border-right:0px;border-bottom:1px; border-bottom-color:Black'
- schedule与scheduleAtFixedRate之Timer源码分析
执行Timer任务调度方法有如下几种: 这些方法最后调用的都是这个方法: private void sched(TimerTask task, long time, long period) 这个 ...
- 111. Minimum Depth of Binary Tree (Tree; DFS)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 99. Recover Binary Search Tree (Tree; DFS)
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- unity与android交互总结
http://www.jianshu.com/p/4739ce2f4cd1 http://www.cnblogs.com/suoluo/p/5443889.html http://www.th7.cn ...
- faster-rcnn目录介绍
data 用来存放pretrained模型,比如imagenet上的,以及读取文件的cache缓存 experiments 存放配置文件以及运行的log文件,另外这个目录下有scripts可以用end ...
- SpringBoot中使用AOP实现计算Service执行时间
1.增加POM.XML的依赖架包 <!-- 引入 spring aop 依赖 --><dependency> <groupId>org.springframewor ...
- 快速搭建Wordpress
1. 下载:ZentaoPMS作为Mysql Apach Php的基础环境: 2. 下载:Wordpress安装包: 3. 将Wordpress解压,放置于ZentaoPMS的Xampp的htdocs ...
- [Training Video - 6] [File Reading] [Java] Read Properties file
package com.file.properties; import java.io.FileInputStream; import java.util.Properties; public cla ...