From c18893e6f31cc74eefb2b4676eee5ca8509ec1c3 Mon Sep 17 00:00:00 2001 From: xRain Date: Mon, 4 May 2026 18:00:58 +0800 Subject: [PATCH] =?UTF-8?q?nginx=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nginx.conf b/nginx.conf index 7b7cb6c..ecd3f7f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -3,6 +3,18 @@ server { root /usr/share/nginx/html; index index.html; + # 👇 跨域配置开始 + add_header Access-Control-Allow-Origin * always; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE' always; + add_header Access-Control-Allow-Headers '*, Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Token' always; + add_header Access-Control-Allow-Credentials 'true' always; + + # 处理预检 OPTIONS 请求 + if ($request_method = 'OPTIONS') { + return 204; + } + # 👆 跨域配置结束 + location / { try_files $uri $uri/ /index.html; }