zoukankan      html  css  js  c++  java
  • 部署asp.net core 2.1到Centos 7

    步骤要点:

    一、关闭Centos selinux:

    操作方式:

    1.永久关闭:打开/etc/selinux/config文件,设置SELINUX=disabled,注意,不是SELINUXTYPE=disabled否则重启后无法进入linux)。

    2.临时关闭,不用重启:setenforce 0    #设置SELinux为permissive模式

    二、安装微软产品密匙及dotnet:

    sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

    再安装asp.net core 2.1:yum -y install dotnet-sdk-2.1

    安装完成后,运行:dotnet -verison可以查看是否安装成功。

    三、上传项目:

    首先在服务器端安装lrzsz工具包,所需命令:yum install lrzsz

    安装完成后,用xshell链接到服务器,并切换到所需上传的目录下,运行命令:rz,然后选择所需文件上传即可。

    四、测试dotnet及项目文件:

    在项目文件目录下,运行 dotnet *****dll,默认启动5000端口,然后在浏览器查看项目运行情况。

    五、安装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

    安装完成后,启动nginx:systemctl start nginx 及 systemctl enable nginx

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

    systemctl restart firewalld

    这时候,还需要配置nginx,打开 /etc/nginx/conf.d/default.conf 文件,修改其server部分,如下:

    server {
        listen       80;
        #server_name  localhost;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
         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;
        }
    }

    之后,运行命令:nginx -s reload,重启nginx

    最终,示例项目运行结果如下:

     另外,在部署时候,需要将Program.cs里面的代码修改如下:

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://*:5000")
                .UseContentRoot(AppContext.BaseDirectory)
                .UseStartup<Startup>();

    发布后,将wwwroot外面的文件转移到wwwroot文件夹内,并运行dotnet *** 即可运行(查看控制台,不再出现404找不到文件情况发生)。

     

    参考文献:http://www.cnblogs.com/ants/p/5732337.html,在此表示感谢。

  • 相关阅读:
    简历的快速复制
    使用stringstream对象简化类型转换
    猴子吃桃
    new和delete运算符
    绘制正余弦曲线
    计算学生的平均成绩
    判断是否为回文字符串
    统计各种字符个数
    验证用户名
    回溯法(挑战编程)
  • 原文地址:https://www.cnblogs.com/jizhong/p/9746272.html
Copyright © 2011-2022 走看看