yzx 1 deň pred
rodič
commit
324b43ea86
2 zmenil súbory, kde vykonal 54 pridanie a 0 odobranie
  1. 16 0
      Dockerfile
  2. 38 0
      nginx.conf

+ 16 - 0
Dockerfile

@@ -0,0 +1,16 @@
+
+
+#基于官方 NGINX 镜像部署(精简镜像)
+FROM nginx:alpine
+
+# 复制本地打包好的 dist 目录到 NGINX 静态资源目录
+COPY ./dist /usr/share/nginx/html
+
+# 替换 NGINX 默认配置(用我们自定义的 nginx.conf)
+COPY ./nginx.conf /etc/nginx/nginx.conf
+
+# 暴露容器端口(与 nginx.conf 中 listen 一致)
+#EXPOSE 80
+
+# 启动 NGINX(前台运行,避免容器启动后退出)
+CMD ["nginx", "-g", "daemon off;"]

+ 38 - 0
nginx.conf

@@ -0,0 +1,38 @@
+# nginx.conf
+worker_processes  5;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    include       mime.types;
+    default_type  application/octet-stream;
+    client_max_body_size 200m;
+    sendfile        on;
+    keepalive_timeout  65;
+
+    server {
+        listen       80;  # 容器内端口
+        server_name  localhost;
+
+        # 前端静态资源目录(对应容器内的 /usr/share/nginx/html)
+        root   /usr/share/nginx/html;
+        index  index.html;
+
+        # 关键:处理 VUE Router history 模式(避免刷新 404)
+        location / {
+            try_files $uri $uri/ /index.html;  # 所有路由指向 index.html
+        }
+
+        # 关键:反向代理 API(解决跨域,替换为你的真实后端地址)
+        location /prod-api/ {
+            proxy_pass http://192.168.58.159:7772/;  # 后端 API 地址(末尾加 / 避免路径拼接问题)
+            proxy_set_header Host $host;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;  # 传递 HTTPS 协议
+        }
+
+     }
+}