fix: add nginx API proxy config for /api/* → backend :3001
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 8s

- Add nginx/longde.cloud.conf with /api/* proxy_pass to localhost:3001
- Update deploy.yml to install nginx config before deploying
- Fixes 405/502 errors when iOS app calls backend API

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
WangDL 2026-05-18 14:06:58 +08:00
parent 5256a4526d
commit 03209e07fc
2 changed files with 60 additions and 0 deletions

View File

@ -23,6 +23,15 @@ jobs:
-w /app \ -w /app \
node:22-alpine sh -c "npm install && npm run build" node:22-alpine sh -c "npm install && npm run build"
- name: Install Nginx config
run: |
mkdir -p /etc/nginx/conf.d 2>/dev/null
cp /tmp/web-projects/nginx/longde.cloud.conf /etc/nginx/conf.d/longde.cloud.conf
# fallback for sites-enabled style
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled 2>/dev/null
cp /tmp/web-projects/nginx/longde.cloud.conf /etc/nginx/sites-available/longde.cloud.conf 2>/dev/null
ln -sf /etc/nginx/sites-available/longde.cloud.conf /etc/nginx/sites-enabled/longde.cloud.conf 2>/dev/null
- name: Deploy to web root - name: Deploy to web root
run: | run: |
rm -rf /var/www/longde.cloud/* rm -rf /var/www/longde.cloud/*

51
nginx/longde.cloud.conf Normal file
View File

@ -0,0 +1,51 @@
server {
listen 80;
server_name longde.cloud www.longde.cloud;
root /var/www/longde.cloud;
index index.html;
# Gzip
gzip on;
gzip_vary on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_types application/json text/plain text/css application/javascript image/svg+xml;
# API proxy to NestJS backend (Docker container on port 3001)
location /api/ {
proxy_pass http://localhost:3001/api/;
proxy_http_version 1.1;
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;
proxy_read_timeout 90s;
proxy_connect_timeout 10s;
client_max_body_size 10m;
}
# Swagger docs
location /api-docs {
proxy_pass http://localhost:3001/api-docs;
proxy_http_version 1.1;
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;
}
location /api-docs-json {
proxy_pass http://localhost:3001/api-docs-json;
proxy_http_version 1.1;
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;
}
# Frontend — SPA fallback
location / {
try_files $uri $uri/ /index.html;
}
}