首页 > 系统相关 >CentOS中使用Docker+nginx部署Vue打包的dist项目

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

时间:2023-02-15 11:06:16浏览次数:49  
标签:index Vue dist log CentOS server nginx html error


场景

CentOS7中Docker的安装与配置

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

注:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

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

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

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

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

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

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

去nginx的网站上下载一个

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

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

添加资源映射

CentOS中使用Docker+nginx部署Vue打包的dist项目_docker

完整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!!'

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

CentOS中使用Docker+nginx部署Vue打包的dist项目_nginx_02

4、构建镜像

在该目录下执行

docker build -t nginxwithdist .

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

输入

docker images

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

CentOS中使用Docker+nginx部署Vue打包的dist项目_nginx_03

5、运行镜像

docker run -p 100:100 -d nginxwithdist

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

CentOS中使用Docker+nginx部署Vue打包的dist项目_nginx_04

 

标签:index,Vue,dist,log,CentOS,server,nginx,html,error
From: https://blog.51cto.com/BADAOLIUMANGQZ/6058741

相关文章

  • CentOS中使用Dockerfile部署带websocket的SpringBoot的jar包
    场景CentOS7中使用Dockerfile部署后台jar包在上面使用Dockerfile定制的镜像部署了一个普通的jar包, 如果是jar包里面包含websocket的使用,流程也是一样。websocket所使用的......
  • CentOS中使用Docker安装Jenkins
    场景CentOS7中Docker的安装与配置首先按照上面在CentOS7中安装Docker注:关注公众号霸道的程序猿获取编程相关电子书、教程推送与免费下载。实现1、搜索镜像dockersearchj......
  • CentOS中使用Dockerfile部署初始化sql文件的mysql
    场景Docker中部署mysql数据库CentOS中使用Dockerfile部署带websocket的SpringBoot的jar包在上面部署Mysql镜像和会使用Dockerfile的基础上。如果要实现定制化一个mysql镜像,......
  • CentOS7中解压tar包的方式安装Nginx
    场景CentOS中怎样安装、配置、启动Nginx:​​CentOS中怎样安装、配置、启动Nginx_BADAO_LIUMANG_QIZHI的博客-博客_centos怎么启动nginx​​上面实现安装nginx的过程简化一下......
  • CentOS7中通过二进制文件与配置环境变量的方式安装Node
    场景Node官网下载地址:​​Download|Node.js​​下载64位二进制文件。注:博客:​​BADAO_LIUMANG_QIZHI的博客_霸道流氓气质_博客-C#,SpringBoot,架构之路领域博主​​关注......
  • CentOS7中通过npm的方式安装Node-RED
    场景Node-RED简介与Windows上安装、启动和运行示例:​​Node-RED简介与Windows上安装、启动和运行示例_BADAO_LIUMANG_QIZHI的博客上面是在Windows上安装node-red,如果要在Ce......
  • CentOS7中后台运行Node-RED(关闭窗口也能访问服务)
    场景CentOS7中通过npm的方式安装Node-RED:​​CentOS7中通过npm的方式安装Node-RED-霸道流氓​​CentOS7中通过npm的方式安装Node-RED_BADAO_LIUMANG_QIZHI的博客​上面运......
  • CentOS7中使用PM2设置Node-RED开机自启动
    场景CentOS7中后台运行Node-RED(关闭窗口也能访问服务):​​CentOS7中后台运行Node-RED(关闭窗口也能访问服务)_BADAO_LIUMANG_QIZHI的博客在上面设置Node-RED后台启动后怎样......
  • CentOS7中使用编译github源码方式离线安装Node-RED
    场景Windows上编译github源码方式运行Node-RED,以及离线迁移安装Node-RED:​​Windows上编译github源码方式运行Node-RED,以及离线迁移安装Node-RED_BADAO_LIUMANG_QIZHI的博......
  • Centos中Redis的下载编译与安装(超详细)
    场景NoSQL,泛指非关系型的数据库,NoSQL即Not-OnlySQL,它可以作为关系型数据库的良好补充。随着互联网web2.0网站的兴起,非关系型的数据库现在成了一个极其热门的新领域,非关系数......