Linux下配置 nginx + .net core 2.0
用到的软件如下
winSCP, vs2017 ,centos 6.8 64位,
安装环境
aliyun centos 6.8 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 新建一个.net core 2.0 的测试代码
可以从此地址下载:http://files.cnblogs.com/file...
使用winSCP把生成好的程序 (webcore/webcore/bin/Debug/netcoreapp2.0/publish下的文件)上传到 /aliyun/www/test 目录下
安装配置nginx
- yum install nginx
- #(如果已安装就不用安装了)
配置nginx.conf
- server {
- listen 80;
- server_name test.uol123.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;
- }
- 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 绑定的域名可以看到网站可以跑起来了 http://test.uol123.com/
到这里基本上就配置好了 nginx + linux + .net core 2.0
如果想要supervisord开机自启动
编辑启动文件
- vi /etc/rc.local
在新行添加要执行的命令
- supervisord -c /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...
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · vue3+vite+多环境发面到二级目录配置
- · nginx http转https, 不带www转带www
- · nginx主动健康检查负载均衡模块
- · nginx自动切换到手机/PC 网站
- · 使用tengine代替Nginx
- · nginx添加nginx_upstream_check_module
- · nginx上传文件超出默认大小限制,提示:413 Request Entity Too Large
- · nginx反向代理禁用缓存
- · docker nginx
- · consul+nginx完成集群服务动态发现和健康检查
- · nginx使用stream模块做ssh转发
- · nginx反向代理wss