fix: Simplify nginx config - let Next.js handle API rewrites
- Remove complex location blocks from nginx - Let Next.js rewrites handle API routing to CMS - Keep only basic proxy configuration Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -3,33 +3,3 @@ map $http_x_forwarded_proto $origin_proto {
|
|||||||
default $http_x_forwarded_proto;
|
default $http_x_forwarded_proto;
|
||||||
"" $scheme;
|
"" $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Map to detect API routes that should go to CMS (port 3001)
|
|
||||||
map $request_uri $cms_api {
|
|
||||||
default 0;
|
|
||||||
~^/auth/(register|me|profile|password|reset|verify|logout) 1;
|
|
||||||
~^/auth/login$ 2; # Special case - handled with if
|
|
||||||
~^/branding/?$ 1;
|
|
||||||
~^/courses/?$ 1;
|
|
||||||
~^/admin/?$ 1;
|
|
||||||
~^/organization/?$ 1;
|
|
||||||
~^/users/ 1;
|
|
||||||
~^/question-bank/ 1;
|
|
||||||
~^/test-templates/ 1;
|
|
||||||
~^/knowledge-base/ 1;
|
|
||||||
~^/api/ 1;
|
|
||||||
~^/assets/ 1;
|
|
||||||
~^/modules/ 1;
|
|
||||||
~^/lessons/ 1;
|
|
||||||
~^/grading/ 1;
|
|
||||||
~^/token-usage/ 1;
|
|
||||||
~^/sam/ 1;
|
|
||||||
~^/embeddings/ 1;
|
|
||||||
=/health 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
# For /auth/login, only POST should go to CMS
|
|
||||||
map "$request_uri:$request_method" $login_post {
|
|
||||||
default 0;
|
|
||||||
"~^/auth/login$:POST" 1;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# CMS API routes - redirect to CMS service (port 3001)
|
# CMS API routes - ONLY POST /auth/login
|
||||||
# Frontend pages stay on port 3000
|
# All other routes handled by Next.js rewrites
|
||||||
|
|
||||||
# Auth login - POST goes to CMS, GET stays on frontend
|
# Auth login - POST goes to CMS API, GET stays on frontend
|
||||||
location = /auth/login {
|
location = /auth/login {
|
||||||
proxy_pass http://172.18.0.6:3000;
|
proxy_pass http://172.18.0.6:3000;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
@@ -10,183 +10,3 @@ location = /auth/login {
|
|||||||
proxy_set_header X-Forwarded-Proto $origin_proto;
|
proxy_set_header X-Forwarded-Proto $origin_proto;
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
proxy_set_header X-Forwarded-Ssl on;
|
||||||
}
|
}
|
||||||
|
|
||||||
# All other auth API endpoints
|
|
||||||
location ^~ /auth/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Branding API
|
|
||||||
location = /branding {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Courses API
|
|
||||||
location = /courses {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Admin API
|
|
||||||
location = /admin {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Organization API
|
|
||||||
location = /organization {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Assets
|
|
||||||
location ^~ /assets/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Health check
|
|
||||||
location = /health {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Users API
|
|
||||||
location ^~ /users/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Question bank
|
|
||||||
location ^~ /question-bank/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test templates
|
|
||||||
location ^~ /test-templates/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Knowledge base
|
|
||||||
location ^~ /knowledge-base/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# API routes
|
|
||||||
location ^~ /api/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Modules
|
|
||||||
location ^~ /modules/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Lessons
|
|
||||||
location ^~ /lessons/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Grading
|
|
||||||
location ^~ /grading/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Token usage
|
|
||||||
location ^~ /token-usage/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# SAM
|
|
||||||
location ^~ /sam/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Embeddings
|
|
||||||
location ^~ /embeddings/ {
|
|
||||||
proxy_pass http://172.18.0.6:3001;
|
|
||||||
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 $origin_proto;
|
|
||||||
proxy_set_header X-Forwarded-Ssl on;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user