docker 安装 nginx 并部署 vue 项目

1、拉取镜像

docker pull nginx

2、创建挂载目录

mkdir -p {/home/nginx/conf,/home/nginx/log,/home/nginx/html}

3、生成容器

docker run --name nginx -p 80:80 -d nginx

4、复制相关配置到宿主机

docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf # 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d         # 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/usr/share/nginx/html /home/nginx/               # 将容器中的html文件夹复制到宿主机

5、删除容器

docker stop nginx  && docker rm nginx

6、启动容器

docker run -p 80:80 --name nginx -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/log:/var/log/nginx -v /home/nginx/html:/usr/share/nginx/html -d nginx:latest

7、修改 /etc/nginx/conf.d/default.conf

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;#
    }
        location  /jeecgboot/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://192.168.1.50:8080/jeecg-boot/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

8、重启 nginx

docker restart nginx
posted @ 2024-07-11 15:58  XuTingYin  阅读(547)  评论(0)    收藏  举报