Linux部署NET5(前后端都有)项目
注:在下是在统信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 前后端分离项目就结束了。有问题请留言,谢谢。

浙公网安备 33010602011771号