CentOS7.6 部署.netcore6.0

2 篇文章 0 订阅
2 篇文章 0 订阅

前置工作
安装宝塔,MYSQL,FTP等软件
宝塔官网

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

目录

  1. 安装.netcore 3.1 SDK
  2. 配置端口
  3. 配置Supervisor守护进程
  4. 配置Nginx反向代理
  5. 运行.netcore项目

安装.netcore 6.0 SDK

# 添加微软官方源
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
# 安装SDK
yum -y install dotnet-sdk-6.0
# 验证安装是否成功
dotnet --info

https 无法访问,可能是443端口未开放

#查看端口开放情况
firewall-cmd --zone=public --list-ports
#开放443/80端口
firewall-cmd --zone=public --add-port=443/tcp --permanent
#重启防火墙
firewall-cmd --reload

配置Supervisor守护进程

安装supervisor

yum -y install supervisor
#启动服务
supervisord -c /etc/supervisord.conf

进入etc/supervisord.d文件夹创建 xxx.ini文件

[program:项目名称]
command=dotnet 项目名称.dll
directory=/www/wwwroot/网站根目录
autostart=true
autorestart=true
startretries=5
startsecs=1
user=root
priority=999
stderr_logfile=/var/log/AbpMPA.err.log
stdout_logfile=/var/log/AbpMPA.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
stopsignal=INT

刷新supervisord配置

supervisorctl reload

查看supervisorctl守护项目状态

supervisorctl
.

配置Nginx反向代理

无SSL证书配置

server
{
    listen 80;
    server_name 网址;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/网站根目录;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/对应文件名.conf;
    #REWRITE-END
    
    location / {
        proxy_pass http://localhost:5000;  #把80端口的访问反向代理到5000端口(你程序的启动端口),请根据实际情况修改自己的端口
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        # 客户端真实ip
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        proxy_pass http://127.0.0.1:5000;
        expires      30d;
        error_log off;
        access_log /dev/null;
    }

    location ~ .*\.(js|css)?$
    {
        proxy_pass http://127.0.0.1:5000;
        expires      12h;
        error_log off;
        access_log /dev/null;
    }
	access_log  /www/wwwlogs/网址.log;
    error_log  /www/wwwlogs/网址.error.log;
}

带SSL证书配置

# 实际websocket服务器地址
upstream wss_svr {
    server 127.0.0.1:39241 weight=1;
}

# http指向https
server {
    listen 80;
    server_name 域名;
    rewrite ^(.*)$ https://${server_name}$1 permanent;
}

server
{
    listen       443 ssl;
    server_name  域名;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/项目目录;
    ssl_certificate      /www/wwwroot/项目目录/SSL/xxx.crt;
    ssl_certificate_key  /www/wwwroot/项目目录/SSL/xxx.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-56.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/配置文件.conf;
    #REWRITE-END
    
    location / {
        proxy_pass http://localhost:5000;  #把80端口的访问反向代理到5000端口(你程序的启动端口),请根据实际情况修改自己的端口
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        # 客户端真实ip
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    location /wss {
        proxy_redirect off;
        proxy_pass http://wss_svr;      # 转发
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;   # 升级协议头
        proxy_set_header Connection upgrade;
    }
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        proxy_pass http://127.0.0.1:5000;
        expires      30d;
        error_log off;
        access_log /dev/null;
    }

    location ~ .*\.(js|css)?$
    {
        proxy_pass http://127.0.0.1:5000;
        expires      12h;
        error_log off;
        access_log /dev/null;
    }
    access_log  /www/wwwlogs/项目名称.log;
    error_log  /www/wwwlogs/项目名称.error.log;
}

重启nginx

nginx -s reload

运行.netcore项目

cd进入网站根目录

dotnet 项目名称.dll
#显示以下内容即成功运行
Hosting environment: Production
Content root path: 网站根目录
Now listening on: http://localhost:5000
Now listening on: http://localhost:5001
Application started. Press Ctrl+C to shut down.

网站成功部署

Centos7发布说明 环境说明: 服务器系统:CentOS 7.2.1511 相关工具:Xshel、Xftp 服务器软件软件:.netcorenginx、supervisor 准备好发布的程序 安装.NET Core SDK for CentOS7 打开网址:https://www.microsoft.com/net/core#linuxcentos 复制如下命令,单步执行: sudo yum install libunwind libicu curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019 sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet sudo ln -s /opt/dotnet/dotnet /usr/local/bin 输入 dotnet –info 来查看是否安装成功 配置Nginx 下载安装Nginx,单步执行如下命令: curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm rpm -ivh nginx.rpm yum install nginx systemctl start nginx 来启动nginx systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。 配置防火墙 命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口) 命令:systemctl restart firewalld(重启防火墙以使配置即时生效) 测试nginx是否可以访问。 配置nginx对ASP.NET Core应用的转发 修改 /etc/nginx/conf.d/default.conf 文件,将文件内容替换为: server { 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; } }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值