Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf-front
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yuzhenWang
yd-csf-front
Commits
a12fa733
Commit
a12fa733
authored
Dec 05, 2025
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置
parent
49a24515
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
22 deletions
+22
-22
nginx.conf
+22
-22
No files found.
nginx.conf
View file @
a12fa733
...
...
@@ -2,8 +2,8 @@
upstream
gateway_load_balance
{
server
139.224.150.79
:
9010
;
# 管理节点服务器上的网关实例
server
139.224.149.150
:
9011
;
# 工作节点服务器上的网关实例
ip_hash
;
#
✅ 新增:
会话粘滞,避免同一用户请求分发到不同网关实例
keepalive
32
;
#
✅ 新增:
保持长连接,提升代理性能
ip_hash
;
# 会话粘滞,避免同一用户请求分发到不同网关实例
keepalive
32
;
# 保持长连接,提升代理性能
}
server
{
...
...
@@ -13,7 +13,7 @@ server {
root
/usr/share/nginx/html
;
index
index.html
;
#
✅ 核心新增
:拦截包含undefined的异常路径,避免无效请求穿透
#
核心
:拦截包含undefined的异常路径,避免无效请求穿透
if
(
$request_uri
~
*
'undefined')
{
rewrite
^(.*)/undefined+(.*)
$
$2
permanent
;
# 清理路径中的undefined片段
rewrite
^/undefined.*
$
/
permanent
;
# 兜底重定向到根路径
...
...
@@ -27,7 +27,7 @@ server {
expires
1y
;
add_header
Cache-Control
"public,
immutable"
;
#
✅ 精简:移除重复的OPTIONS处理(统一在server级处理更高效)
#
CORS头
add_header
'Access-Control-Allow-Origin'
'*'
always
;
add_header
'Access-Control-Allow-Methods'
'GET,
POST,
PUT,
DELETE,
OPTIONS'
always
;
add_header
'Access-Control-Allow-Headers'
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
always
;
...
...
@@ -36,14 +36,14 @@ server {
# 代理API请求到网关服务
location
/api/
{
proxy_pass
http://gateway_load_balance/
;
rewrite
^/api/(.*)
$
/
$1
break
;
#
✅ 新增:
确保/api前缀被正确移除,避免路径错误
rewrite
^/api/(.*)
$
/
$1
break
;
# 确保/api前缀被正确移除,避免路径错误
# 代理设置
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_set_header
Authorization
$http_authorization
;
#
✅ 新增:
传递认证头
proxy_set_header
Authorization
$http_authorization
;
# 传递认证头
# 超时设置
proxy_connect_timeout
30s
;
...
...
@@ -52,17 +52,25 @@ server {
# 缓冲区设置(优化)
proxy_buffering
on
;
proxy_buffer_size
16k
;
# ✅ 调整:提升缓冲区大小,适配API响应
proxy_buffer_size
16k
;
proxy_buffers
8
16k
;
# CORS头
(精简)
# CORS头
add_header
'Access-Control-Allow-Origin'
'*'
always
;
add_header
'Access-Control-Allow-Methods'
'GET,
POST,
PUT,
DELETE,
OPTIONS'
always
;
add_header
'Access-Control-Allow-Headers'
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
always
;
}
# ✅ 新增:统一处理所有OPTIONS预检请求(避免重复配置)
# 健康检查接口
location
/health
{
access_log
off
;
return
200
"healthy
\
n"
;
add_header
Content-Type
text/plain
;
}
# 合并后的location /:同时处理OPTIONS请求和前端路由(核心修复)
location
/
{
# 1. 处理OPTIONS预检请求(整合原重复块的逻辑)
if
(
$request_method
=
'OPTIONS')
{
add_header
'Access-Control-Allow-Origin'
'*'
;
add_header
'Access-Control-Allow-Methods'
'GET,
POST,
PUT,
DELETE,
OPTIONS'
;
...
...
@@ -72,26 +80,17 @@ server {
add_header
'Content-Type'
'text/plain
;
charset=UTF-8'
;
return
204
;
}
}
# 健康检查接口
location
/health
{
access_log
off
;
return
200
"healthy
\
n"
;
add_header
Content-Type
text/plain
;
}
# 前端路由处理 - 放在最后,作为兜底规则
location
/
{
try_files
$uri
$uri
/
/index.html
;
# 处理Vue路由history模式
# 2. 前端路由处理(SPA history模式)
try_files
$uri
$uri
/
/index.html
;
# CORS头
#
3.
CORS头
add_header
'Access-Control-Allow-Origin'
'*'
always
;
add_header
'Access-Control-Allow-Methods'
'GET,
POST,
PUT,
DELETE,
OPTIONS'
always
;
add_header
'Access-Control-Allow-Headers'
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'
always
;
}
#
✅ 新增:
日志配置(便于排查undefined路径等问题)
# 日志配置(便于排查undefined路径等问题)
access_log
/var/log/nginx/csf-front-access.log
main
;
error_log
/var/log/nginx/csf-front-error.log
warn
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment