继上一篇, 我们确定在内网可以通过 “http://localhost:5000”,可以访问到站点后,接下来我们要配置“守护进程”,“Nginx公网80端口访问”

1. 守护进程配置

a) 创建kestrel-hellomvc.service 文件

sudo vim /etc/systemd/system/kestrel-hellomvc.service

b) 粘贴以下内容

[Unit]
Description=Example .NET Web API Application running on CentOS

[Service]
WorkingDirectory=/var/aspnetcore/hellomvc
ExecStart=/usr/local/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

c) 保存配置文件

:wq

d) 通过systemctl 管理服务

#启动守护进程

sudo systemctl start kestrel-hellomvc.service

#开机启动

sudo systemctl enable kestrel-hellomvc.service

-------------------------------------------------------------

常用命令

#启动进程

systemctl start ???

#停止进程

systemctl stop ???

#重新加载

systemctl reload ???

#状态

systemctl status ???

#开机启动

systemctl enable ???

#禁止开机启动

systemctl disable ???

d) 测试

有看到这句就是运行中了

PS: “www-data”CentOS无此用户,记得要先创建好,分配好权限

sudo useradd –M –s /sbin/nologin www-data

sudo chown www-data:root /var/aspnetcore/hellomvc

2. Nginx配置

a) 安装 nginx

sudo yum install nginx

b) 启动 nginx

sudo systemctl start nginx

sudo systemctl enable nginx

c) 配置反向代理

sudo vim /etc/nginx/sites-available/default

erver {
    listen 80;
    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;
    }
}

d) 重启反向代理

sudo systemctl reload nginx

e) 外网访问

PS: 如果访问不到,请检查防火墙是否开启,是否开放了80端口:

# 查看当前端口监听列表

netstat –tln

# 查看firewalld状态

sudo systemctl status firewalld

# 启动firewalld

sudo systemctl start firewalld

# 开机启动firewalld

sudo systemctl enable firewalld

# 查看80端口是否开放

firewall-cmd --query-port=80/tcp

# 开放80端口(—permanent 表示永久开放)

firewall-cmd --permanent --add-port=80/tcp

上一篇: .NET Core 部署到CentOS–1.创建项目,简单部署

下一篇: .NET Core 部署到CentOS–3.supervisord守护进

参考资料:

https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction

https://linux.cn/article-5926-1.html

.NET Core 部署到CentOS–2.创建守护进程, 通过Nginx公网访问的更多相关文章

  1. .NET Core 部署到CentOS–1.创建项目,简单部署

    开发环境:Windows 10,部署环境:阿里云 CentOS 7.3 1. 创建应用 1) 创建项目, 配置应用生成部署包 2) 配置项目 编辑project.json, 追加环境项, 选项可参考这 ...

  2. .NET Core 部署到CentOS–3.supervisord守护进

    1. 安装 sudo yum install python-setuptoolssudo easy_install supervisor 2. 配置 安装成功后,输入supervisord 会显示配置 ...

  3. ASP.NET Core Linux下为 dotnet 创建守护进程(必备知识)

    前言 在上篇文章中介绍了如何在 Docker 容器中部署我们的 asp.net core 应用程序,本篇主要是怎么样为我们在 Linux 或者 macOs 中部署的 dotnet 程序创建一个守护进程 ...

  4. ASP.ENT Core Linux 下 为 donet创建守护进程(转载)

    原文地址:http://www.cnblogs.com/savorboard/p/dotnetcore-supervisor.html 前言 在上篇文章中介绍了如何在 Docker 容器中部署我们的 ...

  5. Supervisor 为服务创建守护进程

    今天需要再服务上部署一个.net 方面的项目:当时开启服务的命令只能在前台执行:使用nohub CMD &等放在后台开启服务都会宕机:所以搜寻了Supervisor 这个解决办法,为服务创建守 ...

  6. 创建守护进程步骤与setsid() -- linux deamon进程

    原创:http://www.cnblogs.com/mickole/p/3188321.html 一,守护进程概述 Linux Daemon(守护进程)是运行在后台的一种特殊进程.它独立于控制终端并且 ...

  7. linux创建守护进程

    守护进程deamon 是一个后台进程,无需用户输入就能运行,用来在系统后台提供某种服务. 常见的守护进程有Wbe服务器.邮件服务器以及数据库服务器等等.守护进程不能控制终端,所以任何的输入和输出都需要 ...

  8. Python中创建守护进程

    python 创建守护进程 python 的os.setdid()提供了类似linux c api的 setsid 也可以通过unix双fork创建守护进程. 几个相关的函数 os.umask(0) ...

  9. linux 创建守护进程的相关知识

    linux 创建守护进程的相关知识 http://www.114390.com/article/46410.htm linux 创建守护进程的相关知识,这篇文章主要介绍了linux 创建守护进程的相关 ...

随机推荐

  1. [Django笔记] 从已有的数据库构建应用

    Django适合从零开始构建,所谓 'Green-field' 开发.那么当我需要基于已存在的数据库构建应用时怎么办呢? inspectdb # 扫描默认数据库 python manage.py in ...

  2. socket 中read返回0的情况

    当client,调用read(socketfd,buffer,n)时,返回0的情况: 1.server端调用了close(soketfd)函数 2.server调用了close(fd,SHUT_WR) ...

  3. JavaScript小技巧随笔

    1. 在用||做条件判断时,如果情况较多,我们可以考虑是否能够用Array.includes()方法代替 var conditionArray = [ test1, test2, test3 ]; i ...

  4. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  5. Windows自动化---模拟鼠标键盘

    1.PyUserInput(不推荐) python2可以使用PyUserInput库:(不推荐) 支持最基础的鼠标,键盘操作,可以剪贴. 安装的时候:pip install PyUserInput 需 ...

  6. FPGA实战操作(1) -- SDRAM(Verilog实现)

    对SDRAM基本概念的介绍以及芯片手册说明,请参考上一篇文章SDRAM操作说明. 1. 说明 如图所示为状态机的简化图示,过程大概可以描述为:SDRAM(IS42S16320D)上电初始化完成后,进入 ...

  7. spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  8. [Groovy] Private fields and methods are not private in groovy

    如题,, 具体介绍请参看: http://refaktor.blogspot.com/2012/07/private-fields-and-methods-are-not.html

  9. js常用代码收集

    1. PC - js 返回指定范围的随机数(m-n之间)的公式 Math.random()*(n-m)+m return false return false // event.preventDefa ...

  10. svg图转canvas,完全阔以的

    遇到的问题:页面中存在svg画的图,也存在canvas图,在用 html2canvas 截取页面的图就导致有图画缺失,至少我需要的缺失了. 一.如果页面单纯的存在一个svg画的图,转为canvas就很 ...