场景

CentOS7中Docker的安装与配置:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119028701

首先按照上面在CentOS7中安装Docker

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、首先打包Vue项目成dist文件

这里采用亲后端分离的快速开发框架

若依前后端分离版手把手教你本地搭建环境并运行项目:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/108465662

然后再服务器上某目录下,这里是在/usr/local下新建dockerfilenginx目录

然后进入该目录,将dist整个目录上传至该目录下。

2、上传nginx的配置文件,nginx.conf

去nginx的网站上下载一个

http://nginx.org/en/download.html

下载一个nginx找到里面的nginx.conf,并修改其内容

添加资源映射

完整nginx.conf文件内容为

#user  nobody;
worker_processes  1;#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;server {listen       100;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   /usr/share/nginx/html;index  index.html index.htm;}#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;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

3、在/usr/local/dockerfilenginx下新建Dockerfile文件

vi Dockerfile

修改其内容为

#基础镜像
FROM nginx
MAINTAINER “霸道的程序猿”
# 将dist文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面
COPY dist/  /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf
RUN echo 'echo nginx with dist init ok!!'

完成以上步骤之后该目录下的文件为

4、构建镜像

在该目录下执行

docker build -t nginxwithdist .

注意后面有个点,代表Dockerfile文件在当前目录

输入

docker images

已经能看到构建好的镜像了

5、运行镜像

docker run -p 100:100 -d nginxwithdist

运行成功之后直接访问CentOS上的100端口查看效果 

CentOS中使用Docker+nginx部署Vue打包的dist项目相关推荐

  1. Docker + Nginx 部署Vue项目

    1.vue项目打包 打包生成dist文件夹 npm run build 如果将该dist目录整个传到服务器上,部署成静态资源站点就能直接访问到该项目. assetsPublicPath: '/' 记得 ...

  2. 使用Docker Nginx部署vue项目

    Vue3 项目打包 打包 Vue 项目在根目录使用以下命令: npm run build 执行以上命令,输出结果如下: 执行完成后,会在 Vue 项目下会生成一个 dist 目录,该目录一般包含 in ...

  3. 在Linux环境下 nginx 部署vue打包项目

    nginx配置反向代理 nginx 常用命令: 在Nginx sbin目录下 cd /www/server/nginx/sbin ./nginx 启动 ./nginx -s reload 重启 ./n ...

  4. CentOS中使用Docker来部署Nginx

    场景 CentOS7中Docker的安装与配置: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119028701 在上面安装好D ...

  5. CentOS中使用Docker来部署Tomcat

    场景 CentOS7中Docker的安装与配置: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119028701 在上面安装好D ...

  6. nginx配置 vue打包后的项目 解决刷新页面404问题|nginx配置多端访问

    访问vue页面时,/# 使url看着不美观,使用 H5 history模式可以完美解决这个问题,但需要后端nginx帮助.接下来我们自己配置一下. 使用前端路由,但切换新路由时,想要滚动到页面顶部,或 ...

  7. 【Vue】Docker + Nginx 部署 Vue3.0 项目

    Docker + Nginx 部署 Vue3.0 项目 1.用指令 npm run build 打包vue.js项目(该项目是在WebStorm里面新建的Vue空项目). 打包成功后,会生成一个目录d ...

  8. 浅谈在centos中使用docker部署war包项目(jsp篇)

    ​ 在centos中使用docker部署war包项目(jsp篇) 一.环境的准备 二.Docker优点 1.简化程序 2.避免选择恐惧症 3.节省开支 三.Docker结构 1.Client( Doc ...

  9. Centos+Nginx部署Vue项目

    Centos+Nginx部署Vue项目 1.项目打包生成dist文件夹 在项目根目录下打开cmd窗口,输入命令 npm run build //生成dist文件夹 2.将dist文件夹上传到cento ...

最新文章

  1. css选择器权重排序_CSS选择器的权重与优先规则
  2. ubuntu 桌面图标设置
  3. linux系统怎样发邮件,linux系统下如何发送邮件
  4. javascript中编码与解码的decodeURI()、decodeURIComponent()区别
  5. idea更新maven依赖包
  6. MQTT工作笔记0006---CONNECT控制报文3
  7. window.external的使用
  8. 病毒分析四:steam盗号病毒
  9. Linux FTP 命令全集
  10. 使用Java写入Excel下拉选择框选项过多不显示问题
  11. 开发管理---项目的范围、时间与成本
  12. 支付行业常见信息安全合规认证小记
  13. 云计算 第四章 微软云计算 Windows Azure
  14. 安卓谷歌浏览器全屏打开HTML
  15. C/C++实例goto语句实现“关机代码”
  16. 什么是端口?端口号分为几种类型?
  17. Git应用教程-姜威-专题视频课程
  18. Modelsim SE-64 10.4建立UVM环境
  19. 毕业两年的大专生程序员工作总结(java后端)
  20. matlab系统辨识尝试之详细过程1,Matlab系统辨识尝试之详细过程1

热门文章

  1. Tomcat的热部署和重新启动和重新部署的关系
  2. 期末数据结构复习稳过不挂指南(更新中)
  3. Oracle分组取出每组的第一笔数据
  4. linux查看发ftp的ip地址,linux常用命令及学习小结(4)--IP设置、samba、ftp
  5. WEB技术架构的资源链接。
  6. Mysql数据库设计及常见问题
  7. git提交代码,合并同步分支
  8. SpringCloud--Eureka服务注册与发现 Eureka 集群搭建 详细案例!!!
  9. foreach无法给外部变量赋值(Local variable decimal defined in an enclosing scope must be final or effectively )
  10. 梯度下降 最小二乘法 matlab,最小二乘法和梯度下降法的理解