7.18 group_buy 尝试部署-3 前端使用nginx.conf进行配置

This commit is contained in:
zhangsan 2025-07-18 16:15:19 +08:00
parent 68aa550658
commit 08ca4575b0
4 changed files with 60 additions and 6 deletions

View File

@ -14,6 +14,7 @@ services:
- '86:80'
volumes:
- ./nginx/html:/usr/share/nginx/html
- ./nginx/conf:/etc/nginx/conf.d:ro
privileged: true
networks:
- group-buy-network

View File

@ -0,0 +1,54 @@
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 124.71.159.195:8091;
}
upstream pay_backend {
server 124.71.159.195: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;
}
}
}

View File

@ -25,7 +25,7 @@ document.addEventListener('DOMContentLoaded', () => {
/* =====================================================
* 1. 取接口数据并渲染
* =================================================== */
const CFG_API = 'http://127.0.0.1:8091/api/v1/gbm/index/query_group_buy_market_config';
const CFG_API = '/api/v1/gbm/index/query_group_buy_market_config';
// 登录检查
const loginToken = getCookie('loginToken');
@ -202,8 +202,7 @@ document.addEventListener('DOMContentLoaded', () => {
/* =====================================================
* 4. 支付相关
* =================================================== */
const PAY_MALL_URL = 'http://127.0.0.1:8092';
const CREATE_PAY_API = `${PAY_MALL_URL}/api/v1/alipay/create_pay_order`;
const CREATE_PAY_API = `/api/v1/alipay/create_pay_order`;
// 4.1 支付确认弹窗
function showPaymentConfirm(price){

View File

@ -1,5 +1,5 @@
/* -------------------- 配置 -------------------- */
const sPayMallUrl = "http://127.0.0.1:8092";
/* -------------------- Cookie 工具 -------------------- */
function setCookie(name, value, days) {
@ -32,7 +32,7 @@ document.addEventListener("DOMContentLoaded", () => {
}
/* ---------- 获取二维码 ticket ---------- */
fetch(`${sPayMallUrl}/api/v1/login/weixin_qrcode_ticket_scene?sceneStr=${sceneStr}`)
fetch(`/api/v1/login/weixin_qrcode_ticket_scene?sceneStr=${sceneStr}`)
.then(res => res.json())
.then(data => {
if (data.code !== "0000") {
@ -57,7 +57,7 @@ document.addEventListener("DOMContentLoaded", () => {
/* -------------------- 轮询检查登录 -------------------- */
function checkLoginStatus(ticket, sceneStr, intervalId) {
fetch(`${sPayMallUrl}/api/v1/login/check_login_scene?ticket=${ticket}&sceneStr=${sceneStr}`)
fetch(`/api/v1/login/check_login_scene?ticket=${ticket}&sceneStr=${sceneStr}`)
.then(res => res.json())
.then(data => {
if (data.code === "0000") {