分类目录

链接

2017 年 12 月
 123
45678910
11121314151617
18192021222324
25262728293031

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > .NET, LINUX > 正文
Linux下配置 nginx + .net core 2.0
.NET, LINUX 暂无评论 阅读(710)

用到的软件如下

winSCP, vs2017 ,centos 6.8 64位,

安装环境

aliyun centos 6.8 64位

安装.net core 2.0 依赖的组件

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

安装.net core 2.0

  1. sudo dnf install libunwind libicu
  2. curl -sSL -o dotnet.tar.gz https://aka.ms/dotnet-sdk-2.0.0-linux-x64
  3. sudo mkdir -/opt/dotnet >> sudo tar zxf dotnet.tar.gz -/opt/dotnet
  4. sudo ln -/opt/dotnet/dotnet /usr/local/bin
  5. dotnet --help

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

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

 

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

可以从此地址下载:http://files.cnblogs.com/file...

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

安装配置nginx

  1. yum install nginx
  2. #(如果已安装就不用安装了)

配置nginx.conf

  1. server {
  2.  
  3.     listen 80;
  4.     server_name  test.uol123.com;
  5.  
  6.     location / {
  7.         proxy_pass http://localhost:5000;
  8.         proxy_http_version 1.1;
  9.         proxy_set_header Upgrade $http_upgrade;
  10.         proxy_set_header Connection keep-alive;
  11.         proxy_set_header Host $host;
  12.         proxy_cache_bypass $http_upgrade;
  13.     }
  14.  
  15.     error_page 404 /404.html;
  16.         location = /40x.html {
  17.     }
  18.  
  19.     error_page 500 502 503 504 /50x.html;
  20.         location = /50x.html {
  21.     }
  22. }

配置守护进程安装Supervisor

  1. yum install Supervisor

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

  1. [program:webcore]
  2. command=dotnet webcore.dll
  3. directory=/home/test
  4. environment=ASPNETCORE__ENVIRONMENT=Production
  5. user=root
  6. stopsignal=INT
  7. autostart=true
  8. autorestart=true
  9. startsecs=3
  10. stderr_logfile=/var/log/webcore.err.log 
  11. stdout_logfile=/var/log/webcore.out.log

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

最后启动

  1. supervisord -/etc/supervisord.conf

执行

  1. nginx -s reload

访问 nginx 绑定的域名可以看到网站可以跑起来了 http://test.uol123.com/

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


如果想要supervisord开机自启动

编辑启动文件

  1. vi /etc/rc.local

在新行添加要执行的命令

  1. supervisord  -/etc/supervisord.conf

常用命令

查看所有action

supervisorctl <span class="hljs-built_in">help</span>

控制所有进程

supervisorctl start <span class="hljs-built_in">all</span>
supervisorctl <span class="hljs-keyword">stop</span> <span class="hljs-built_in">all</span>
supervisorctl restart <span class="hljs-built_in">all</span>

控制目标进程

supervisorctl stop <span class="hljs-keyword">shadowsocks
</span>supervisorctl start <span class="hljs-keyword">shadowsocks
</span>supervisorctl restart <span class="hljs-keyword">shadowsocks
</span>

参考资料

Set up a hosting environment for ASP.NET Core on Linux with Nginx, and deploy to it
https://docs.microsoft.com/en...

Prerequisites for .NET Core on Linux
https://docs.microsoft.com/en...

ASP.NET Core Linux下为 dotnet 创建守护进程(必备知识)
http://www.cnblogs.com/savorb...

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:Linux下配置 nginx + .net core 2.0 | Bruce's Blog

发表评论

留言无头像?