首页 技术 正文
技术 2022年11月15日
0 收藏 961 点赞 3,780 浏览 1892 个字

在Linux上部署.net core 2.0程序:

第一步:配置Nginx代理

在/etc/nginx/sites-available/default 中添加

server {
listen ;
location /{
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

这样,访问80端口,就可以直接访问到localhost:5000端口了

第二步:如果一台服务器里要运行多个站点,就要配置Nginx 按照域名转发

server {
listen ;
server_name test1.api.com;
location /{
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}server {
listen ;
server_name test2.api.com;
location /{
proxy_pass http://localhost:5001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

这样的话,通过域名 test1.api.com:80 访问就是localhost:5000的站点,通过域名test2.api.com:80 访问的就是localhost:5001的站点

/etc/nginx/nginx.conf 中的http{}中加入:

 include /etc/nginx/sites-enabled/*;

测试新增的配置是否正确

nginx -t

重新加载配置

nginx -s reload

第三步:设置守护进程

设置守护进程有很多方法,这里介绍利用Linux中的系统服务管理工具 Systemctl 。也是很方便的。

在/etc/systemd/system/ 文件夹下,新建一个test.service

[Unit]
Description = CNBlogs.ZzkService running on Ubuntu[Service]
WorkingDirectory = /test
ExecStart =/usr/bin/dotnet /test/bin/Debug/netcoreapp2./CNBlogs.ZzkService.WebApi.dll
Restart = always
RestartSec =
SyslogIdentifier = dotnet-example
User = root
Environment = ASPNETCORE_ENVIRONMENT=ProductionEnvironment = DOTNET_PRINT_TELEMETRY_MESSAGE=false

ExecStart 是运行命令

RestartSec 是每3秒检查一次

启动服务

systemctl enable test.service
systemctl start test.service

查看服务运行状态

systemctl status test.service

会出现类似下面的状态,表示运行正确:

● kestrel-hellomvc.service - Example .NET Web API Application running on Ubuntu
Loaded: loaded (/etc/systemd/system/kestrel-hellomvc.service; enabled)
Active: active (running) since Thu -- :: NZDT; 35s ago
Main PID: (dotnet)
CGroup: /system.slice/kestrel-hellomvc.service
└─ /usr/local/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902