Loading... > 主要针对浏览器预检请求做处理 ```nginx server { listen 8100; server_name 127.0.0.1; # 本地开发,使用 localhost location / { # 指定后端服务器地址 proxy_pass http://dome.com; # 添加 HTTP 头部,实现 CORS #add_header 'Access-Control-Allow-Origin' 'http://172.29.96.1:3000'; #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; #add_header 'Access-Control-Allow-Headers' 'Authorization, Referer, User-Agent, Content-Type'; #add_header 'Access-Control-Expose-Headers' 'Authorization, Content-Type'; # 处理预检请求 if ($request_method = 'OPTIONS') { # 指定允许的域名,使用*通配符也可以 add_header 'Access-Control-Allow-Origin' 'http://172.29.96.1:3000'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Authorization, Referer, User-Agent, Content-Type'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } } } ``` 最后修改:2025 年 03 月 12 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏