Browse Source

首次提交

alair 4 tháng trước cách đây
mục cha
commit
88aeec638e
2 tập tin đã thay đổi với 70 bổ sung0 xóa
  1. 3 0
      docker/Dockerfile
  2. 67 0
      docker/nginx.conf

+ 3 - 0
docker/Dockerfile

@@ -0,0 +1,3 @@
+FROM nginx:latest
+COPY dist/ /usr/share/nginx/html
+COPY nginx.conf /etc/nginx/conf.d/default.conf

+ 67 - 0
docker/nginx.conf

@@ -0,0 +1,67 @@
+# 全局配置
+user  nginx;
+worker_processes  auto;  # 自动根据 CPU 核心数设置 worker 进程数
+
+error_log  /var/log/nginx/error.log warn;
+pid        /var/run/nginx.pid;
+
+# 事件模块配置
+events {
+    worker_connections  1024;  # 每个 worker 进程的最大连接数
+}
+
+# HTTP 服务器配置
+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;                    # 开启 Gzip 压缩
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
+
+    # 反向代理配置
+    upstream backend {
+        server ruoyi_admin:18081;     # 后端服务(K8s Service 名或 IP:Port)
+    }
+
+    # 虚拟主机配置(前端 + 反向代理 API)
+    server {
+        listen       80;          # 监听端口
+        server_name  localhost;   # 域名或 IP
+
+        # 前端静态文件
+        location / {
+            root   /usr/share/nginx/html;  # Vue/React 打包后的 dist 目录
+            index  index.html;
+            try_files $uri $uri/ /index.html;  # 支持 Vue/React 前端路由
+        }
+
+        # 后端 API 代理
+        location /api {
+            proxy_pass http://backend;  # 转发到后端服务
+            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_connect_timeout 60s;
+            proxy_read_timeout 60s;
+        }
+
+        # 错误页面
+        error_page   500 502 503 504  /50x.html;
+        location = /50x.html {
+            root   /usr/share/nginx/html;
+        }
+    }
+}