docker + nginx部署vue项目

前置工作需要完成:
安装完成docker 

安装完成nginx镜像,命令:docker pull nginx

开始配置nginx

1、创建nginx的配置文件

在宿主机我喜欢用mydata存储挂载的文件,比如我nginx所有的挂载文件都在/mydata/nginx目录下

在/mydata/nginx/config 目录下 创建一个nginx.conf 配置文件,内容如下:

user  nginx;
worker_processes  4;
 
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
 
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    #gzip  on;
 
    #include /etc/nginx/conf.d/*.conf;
   
    underscores_in_headers on;
 
    client_max_body_size 1024m;
 
    server {
            listen       31000;
            listen       [::]:31000;
            server_name  _;
 
            # 项目目录
            root         /home/nginx/dist;
           
            # Load configuration files for the default server block.
           
            #include /etc/nginx/default.d/*.conf;
 
            location / {
                root            /home/nginx/dist;
                index index.html index.htm;
                try_files $uri $uri/ /index.html;
            }
 
            error_page 404 /404.html;
            location = /404.html {
            }
           
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
            }
    }
}

2、将打包好的vue项目放在/mydata/nginx/dist目录下

3、执行运行命令并挂载文件

 docker run -it \
 --name nginx \
 --hostname=nginx \
 --privileged=true -u root \
 --restart=always \
 -v /mydata/nginx/dist:/home/nginx \
 -v /mydata/nginx/config/nginx.conf:/etc/nginx/nginx.conf \
 -v /mydata/nginx/log:/var/log/nginx/ \
 -p 31000:31000 -d nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值