1. 首页>
  2. 技术文章>
  3. EntityFrameWorkCore发布到centos

EntityFrameWorkCore发布到centos

5/21/17 9:57:35 AM 浏览 1804 评论 0

dotnetcore EntityFrameWorkCore centos linux Nginx

使用VS开发完代码之后,可以本地发布好,直接上传到centos或其它linux系统,就可以直接访问ASP.NET Core代码了,在1.1的版本中,已经没有了Project.json这个文件了,而是使用.csproj文件。不过我们本地发布好测试好之后,上传我们本地发布的版本,是不用管这两个文件的,除非需要到服务器上去还原包。本地生成Centos包,命令如下:

dotnet publish -f netcoreapp1.1 --runtime centos.7-x64

这里centos.7-x64可以参考:https://docs.microsoft.com/zh-cn/dotnet/articles/core/rid-catalog,有其它系统对应的写法,然后,使用WinScp或其它工具上传到Centos中去,定位到发布后的目录 ,运行命令(&表示在后台运行,如果不需要可以不加):

dotnet yourapplication.dll &

看能否运行成功,成功的话,会提示

Now listening on :http://127.0.0.1:81

而这里的81端口是我在Program.cs中添加的代码,添加后如下:

var host = new WebHostBuilder()
    .UseUrls("http://127.0.0.1:81")
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>()
    .UseApplicationInsights()
    .Build();

host.Run();

Centos要安装.net core的运行环境,这个直接用微软官方的指导,链接:https://www.microsoft.com/net/core#linuxcentos再配合Nginx,当然需要在Nginx配置,如下:

server
{
    listen 80;
    server_name www.52jiagou.com;
    index index.html index.htm default.htm default.html;
    root /www/wwwroot/www.52jiagou.com;
    #error_page 404/404.html;
    error_page 404 /404.html;
    error_page 502 /502.html;
    
    #include enable-php-54.conf;
    #include /www/server/panel/vhost/rewrite/www.52jiagou.com.conf;
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        access_log off; 
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        access_log off; 
    }
     location / {
         proxy_pass http://127.0.0.1:81/;
         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;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    access_log  /www/wwwlogs/www.52jiagou.com.log;
}


网友讨论