user  nginx;
worker_processes  auto;
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;
  sendfile        on;
  keepalive_timeout  65;

  # 上游后端定义
  upstream gbm_backend {
    server group-buying-sys:8091;
  }
  upstream pay_backend {
    server pay-mall:8092;
  }

  server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    # 不写 server_name，就用默认
    server_name  groupbuy.bitday.top;

    # 1. 提供前端静态文件
    root /usr/share/nginx/html;      # 改成你的打包目录
    index index.html;

    location / {
      try_files $uri $uri/ /index.html;
    }

    # 2. 所有 /api/v1/gbm/* 转给 8091
    location /api/v1/gbm/ {
      proxy_pass         http://gbm_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;
    }

    # 3. 所有 /api/v1/alipay/* 和 /api/v1/login/* 转给 8092
    location ~ ^/api/v1/(alipay|login)/ {
      proxy_pass         http://pay_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;
    }
  }
}
