用到的软件如下

xshell,xftp,vs2017.3,centos 7.3 64位

安装环境

aliyun centos 7.3 64位

安装.net core 2.0 依赖的组件

yum install deltarpm epel-release unzip libunwind gettext libcurl-devel openssl-devel zlib libicu-devel

安装.net core 2.0

sudo dnf install libunwind libicu
curl -sSL -o dotnet.tar.gz https://aka.ms/dotnet-sdk-2.0.0-linux-x64
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
dotnet --help

在命令 dotnet --help 看到下面信息就安装.net core 2.0成功了

[root@iZ6r8lfyydxll0Z ~]# dotnet --help
.NET Command Line Tools (2.0.0)
Usage: dotnet [runtime-options] [path-to-application]
Usage: dotnet [sdk-options] [command] [arguments] [command-options] path-to-application:
The path to an application .dll file to execute.

使用VS2017.3 新建一个.net core 2.0 的测试代码

使用xftp 把生成好的程序 (webcore/webcore/bin/Debug/netcoreapp2.0/publish下的文件)上传到 /home/test 目录下

安装配置nginx

yum install nginx

配置nginx.conf

server {

    listen 80;
server_name test.fun5.cn; 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;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

配置守护进程安装Supervisor

yum install Supervisor

Supervisor配置文件,创建一个ini 配置文件 webcore.ini

[program:webcore]
command=dotnet webcore.dll
directory=/home/test
environment=ASPNETCORE__ENVIRONMENT=Production
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3
stderr_logfile=/var/log/webcore.err.log
stdout_logfile=/var/log/webcore.out.log

创建好之后,使用 xftp 上次到 /etc/supervisord.d 目录下

最后启动

supervisord -c /etc/supervisord.conf

执行 nginx -s reload

访问 nginx 绑定的域名可以看到网站可以跑起来了

到这里基本上就配置好了 nginx + linux + .net core 2.0


如果想要supervisord开机自启动

编辑启动文件

vi /etc/rc.local

在新行添加要执行的命令

supervisord  -c /etc/supervisord.conf

常用命令

查看所有action

 
supervisorctl help

控制所有进程

supervisorctl start all
supervisorctl stop all
supervisorctl restart all

控制目标进程

supervisorctl stop shadowsocks
supervisorctl start shadowsocks
supervisorctl restart shadowsocks
04-25 10:16