Vue部署到Docker
参考文档:手把手教你用 Docker 部署 Vue3 项目_docker部署vue3项目-CSDN博客
参考文档:dockerfile 部署前端vue项目_vue dockerfile-CSDN博客
nginx文档:使用docker安装nginx - 静以修身俭以养德 - 博客园 (cnblogs.com)
结合使用了两个文档的方法和DockerFIle
区别
第一篇使用的是删除nginx默认的 default.conf配置文件然后通过DockerFile进行替换
server {
listen 80;
server_name localhost; # 修改为docker服务宿主机的ip
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
DockerFile
FROM nginx:该镜像是基于nginx:latest镜像构建的
MAINTAINER onesummer:添加说明
RUN rm /etc/nginx/conf.d/default.conf:删除目录下的default.conf文件
ADD default.conf /etc/nginx/conf.d/:将default.conf复制到/etc/nginx/conf.d/下,用本地的default.conf配置来替换nginx镜像里的默认配置
COPY dist/ /usr/share/nginx/html/:将项目根目录下dist文件夹(构建之后才会生成)下的所有文件复制到镜像/usr/share/nginx/html/目录下
第二篇是通过替换nginx默认的nginx.conf使用DockerFIle进行替换
同时需要去创建三个文件夹,然后去替换默认的index
//nginx.conf文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
server {
listen 80;
listen [::]:80;
client_max_body_size 20m;
client_body_buffer_size 1m;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#生产环境接口反向代理配置
location /stage-api/ {
#保留代理之前的host 包含客户端真实的域名和端口号
proxy_set_header Host $http_host;
#保留代理之前的真实客户端ip
proxy_set_header X-Real-IP $remote_addr;
#这个Header和X-Real-IP类似,但它在多级代理时会包含真实客户端及中间每个代理服务器的IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#表示客户端真实的协议(http还是https)
proxy_set_header X-Forwarded-Proto $scheme;
#写后端服务端口
proxy_pass http://192.168.1.164:29097/;
}
#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 /usr/share/nginx/html;
}
}
}
Docker
FROM nginx
# 作者信息
MAINTAINER lxp
# 挂载目录
VOLUME /usr/share/nginx/html
# 复制conf文件到路径
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
# 复制html文件到路径
COPY ./html /usr/share/nginx/html
结合
因为我是修改nginx.conf文件同时,并且不想要去创建额外的文件夹所以我就使用了两者结合的方法
Dockerfile
FROM nginx
MAINTAINER onesummer
RUN rm /etc/nginx/nginx.conf //删除默认的nginx.conf
ADD nginx.conf /etc/nginx/ //添加nginx.conf
COPY dist/ /usr/share/nginx/html/
因为我们使用的Element-admin所以需要对nginx.conf做出一定的修改,参照第二篇进行修改
标签:index,http,log,部署,nginx,html,conf,net,Docker From: https://www.cnblogs.com/zhaoshiyi/p/18339201