Note first use of NET CORE 2.2 DEMO done on-line and deployed LINUX

.NET CORE for so long without success to play through, and today it took a little time to do a small DEMO, for the first time and complete the deployment on the line. Record it.

D EMO test in just a moment to get data from MSSQL, and displayed on the page, related to the database connection, and the associated deployment steps. Until binding domain.

The final line of the URL: http://test.core.68weitang.cn/  due to a server that is a period of time expires, the URL may not be able to access the relevant source code attached recently.

Project structure:

 

Business class libraries referenced item, Business achieve specific business service layer, connecting the item only MSSQL database, acquire 10 random data is converted into List <AccountVO> object.

Layouts Business project is to call the business layer to get data list. code show as below:

Background code.

After the code is complete, you can publish.

Work of the entire code section is complete, then we do the work of the deployment.

The test server is Ali cloud of a minimum configuration of ECS, 1 Ge CPU, 500M memory, the system installed version of CentOS 7.6.

Prior to the environment has been installed above the linux big problem, upload the file you want to install XFTP, WEB server to use nginx, etc., for not played LINUX how deeply people a headache. Pagoda later found the software very easy to use, highly recommended, installation is relatively simple.

Official documents address: https://www.bt.cn/bbs/thread-19376-1-1.html , in fact, a command on the line, very simple. After the installation is complete, the user name and password pagoda, this next record it will be used later. Like the following

Installation pagoda, mainly to solve IN LINUX upload files, configuration WEB server, etc., more convenient, this does not have to be installed, if LINUX experience more adequate, you can do this. The following is based on my page pagoda operation.

 

将我们发布的CORE的程序,打包截图如下。

登录宝塔:点击左侧的文件菜单,下面是截图示例。

点击上传

选中当前的文件,点右下角的开始上传,如果碰到文件上传的失败的问题,有可能是宝塔的版本的问题,或是文件太大,这个我碰到过。

文件后面有个解压的操作项,直接解压就行 。

 

解压完成之后,整体目录下面就是这样了。

 

打开CRT软件,使用ROOT登录上服务器之后,用这个命令 dotnet --info,看一下是否有效,如果无效,就说明没有安装NET CORE,我这个DEMO是使用的CORE 2.2,打开微软的安装地址,选择对应的服务器安装即可。

https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install  需要注意的是,要选择对应的服务器。

 

安装完成之后,再输入dotnet --info 应该就显示和我上面的截图一样了。

 

咱们回到CRT中来,宝塔的中上传的文件,一般是放在www/wwwroot/目录下,CRT里面用CD /www/wwwroot/即可到了该目录。这个我还找了半天,不会玩的人真是醉了。

cd之后,可以用ls查看一下目录,我截图大家看一下。

上面能看到我们所有发布的WEB文件了,因为己经在宝塔里面解压了,当然咱们的ZIP那个压缩文件也在。

再使用 dotnet web项目名称.dll,我们这个项目的命令大概是这个样子

dotnet DN.Core.Layouts.Web1.dll

下面的截图能看到启动了4001和4002两个端口

这个说明就成功了。

一般情况下,用服务器加端口的方式应该是能访问的。我这里面因为要用域名访问,所以需要在宝塔中安装nginx服务器做转发。

进入宝塔页面,左侧菜单 软件商店,安装即可。安装完成后有个设置项,如下截图。

 

设置里面需要配置域名和对应的转发端口,即80对应的域名转发到咱们的4001服务上。

我把这个项目中使用的配置文件放在这里,大家可以参考一下。

  1 user  www www;
  2 worker_processes auto;
  3 error_log  /www/wwwlogs/nginx_error.log  crit;
  4 pid        /www/server/nginx/logs/nginx.pid;
  5 worker_rlimit_nofile 51200;
  6 
  7 events
  8     {
  9         use epoll;
 10         worker_connections 51200;
 11         multi_accept on;
 12     }
 13 
 14 http
 15     {
 16         include       mime.types;
 17         #include luawaf.conf;
 18 
 19         include proxy.conf;
 20 
 21         default_type  application/octet-stream;
 22 
 23         server_names_hash_bucket_size 512;
 24         client_header_buffer_size 32k;
 25         large_client_header_buffers 4 32k;
 26         client_max_body_size 50m;
 27 
 28         sendfile   on;
 29         tcp_nopush on;
 30 
 31         keepalive_timeout 60;
 32 
 33         tcp_nodelay on;
 34 
 35         fastcgi_connect_timeout 300;
 36         fastcgi_send_timeout 300;
 37         fastcgi_read_timeout 300;
 38         fastcgi_buffer_size 64k;
 39         fastcgi_buffers 4 64k;
 40         fastcgi_busy_buffers_size 128k;
 41         fastcgi_temp_file_write_size 256k;
 42         fastcgi_intercept_errors on;
 43 
 44         gzip on;
 45         gzip_min_length  1k;
 46         gzip_buffers     4 16k;
 47         gzip_http_version 1.1;
 48         gzip_comp_level 2;
 49         gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
 50         gzip_vary on;
 51         gzip_proxied   expired no-cache no-store private auth;
 52         gzip_disable   "MSIE [1-6]\.";
 53 
 54         limit_conn_zone $binary_remote_addr zone=perip:10m;
 55         limit_conn_zone $server_name zone=perserver:10m;
 56 
 57         server_tokens off;
 58         access_log off;
 59 
 60 server
 61     {
 62         listen 888;
 63         server_name phpmyadmin;
 64         index index.html index.htm index.php;
 65         root  /www/server/phpmyadmin;
 66 
 67         #error_page   404   /404.html;
 68         include enable-php.conf;
 69 
 70         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 71         {
 72             expires      30d;
 73         }
 74 
 75         location ~ .*\.(js|css)?$
 76         {
 77             expires      12h;
 78         }
 79 
 80         location ~ /\.
 81         {
 82             deny all;
 83         }
 84 
 85         access_log  /www/wwwlogs/access.log;
 86         
 87          listen       80;
 88         server_name  test.core.68weitang.cn;
 89 
 90         location / {
 91             proxy_pass http://127.0.0.1:4001;
 92             proxy_http_version 1.1;
 93             proxy_set_header Upgrade $http_upgrade;
 94             proxy_set_header Connection keep-alive;
 95             proxy_set_header Host $host;
 96             proxy_set_header X-Real-IP $remote_addr;
 97             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 98             proxy_cache_bypass $http_upgrade;
 99         }
100     }
101 include /www/server/panel/vhost/nginx/*.conf;
102 }

其中的87-99行是我加的代码,从域名映射到4001的端口。大家可以参考一下。

然后打开上面的域名就可以了。

 

另外,在这个过程中,阿里云的ECS可能会对端口有限制,这个需要在阿里云里面进行相关的设置。

 

第一次将CORE的程序跑在LINUX服务器上还是比较开心的,个人感觉难点,还是在LINUX服务器的安装配置这块,如果没用宝塔,真的是好麻烦,自己以前也用LINUX配置过,在安装部署的过程就是碰到各种问题,一直没有将CORE的程序发布成功,这次用了一下宝塔,感觉还是比较方便的。

代码有些是从其它项目中摘过来的,可能很不规范,因为只是做个示例DEMO。

 

文件下载地址,https://files.cnblogs.com/files/sp1086/DN.Core.Sample.zip 

换成百度网盘吧,博客园的下载不好使了。

链接: https://pan.baidu.com/s/1zjmXUiDaINN_IdFOnseXUA 提取码: 49k5  

Guess you like

Origin www.cnblogs.com/sp1086/p/11316741.html