ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux部署NET5(前后端都有)项目

2022-02-17 12:35:15  阅读:156  来源: 互联网

标签:index log 部署 error nginx html Linux NET5 docker


注:在下是在统信UOS系统(Ubuntu系统)中安装部署的。

一、Docker安装

1.安装docker:
sudo apt install docker.io

2.查看docker版本:
docker -v 或者 docker --version

 二、Dckerfile文件内容

#Dockerfile文件内容如下:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 5005
EXPOSE 443
COPY . .
ENTRYPOINT ["dotnet", "LanTai.System.Hostd.dll"]

RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /usr/lib/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl.cnf

# install libgdiplus for System.Drawing
RUN apt-get update && \
    apt-get install -y --allow-unauthenticated libgdiplus libc6-dev

三、在VS里面编译发布,然后用工具上传文件到Linux系统。我用的是WinScp,远程登录Linux如果登录不了要运行下命令:sudo service ssh start 这个命令是用来启动ssh的。

四、建立Docker镜像、建立Docker容器

#创建镜像
docker build -t 镜像名称 . 

#查询镜像是否创建成功
docker images

#创建容器
docker run -d -p 5005:5005 --name 容器名称 镜像名称

#查询容器是否创建成功
docker ps -a

五、部署前端Vue项目 

我用的是nginx来跑Vue项目的,先安装nginx

#Nginx安装
docker pull nginx:latest

#查看nginx进程
ps aux|grep nginx

  

#编译Vue项目
npm run build:prod

然后用工具上传文件到Linux系统。

前端Vue项目Dockerfile内容

FROM nginx

EXPOSE 80
EXPOSE 5006

COPY dist/ /usr/local/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf

RUN echo 'echo init ok!!'

ENTRYPOINT nginx -g "daemon off;"

nginx.conf内容

worker_processes auto;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
  
#pid        logs/nginx.pid;
 
events {
    worker_connections  1024;
}
   
http {
    include       mime.types;
    default_type  application/octet-stream;
  
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
  
    #access_log  logs/access.log  main;
  
    sendfile        on;
    #tcp_nopush     on;
  
    #keepalive_timeout  0;
    keepalive_timeout  65;
  
    #gzip  on;
  
    client_max_body_size   20m;
    server {
        listen       5006;
        server_name  localhost;
  
        #charset koi8-r;
  
        #access_log  logs/host.access.log  main;
     location / {
        root   /usr/local/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
        }
        #error_page  404              /404.html;
  
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
  
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
  
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
  
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
  
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
  
}

六、重复第四步=》建立Docker镜像、建立Docker容器。

到此Linux部署NET5 前后端分离项目就结束了。有问题请留言,谢谢。

标签:index,log,部署,error,nginx,html,Linux,NET5,docker
来源: https://www.cnblogs.com/AlbertSmith/p/15904021.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有