nginx 配置跨域(小皮面板)

本地开发的时候,前端请求后端,后端不能用域名请求,只能用端口模式,在小皮面板的话就是如下配置:

我的测试项目部署:

前端:http://localhost:8082

后端:http://localhost:8081

前端请求后端接口的时候会出现跨域问题,这里是nginx配置跨域:

只需要在后端8081端口的nginx.conf文件中配置即可

配置如下,方便复制:

复制代码
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

if ($request_method = 'OPTIONS') {
	return 204;
}
相关推荐
QH139292318807 小时前
# R&S ZNB43 ZNA43 ZNA67矢量网络分析仪
开发语言·网络·php
名字还没想好☜9 小时前
Python concurrent.futures 实战:用 ThreadPoolExecutor 并发处理 + as_completed 收结果
数据库·python·php·并发
风样滴男人哟10 小时前
PHP特性之反射类ReflectionClass机制
android·开发语言·php
nvd1110 小时前
GCP L4 Passthrough 负载均衡器“假死超时”深度排查复盘
运维·php·负载均衡
2601_9657984712 小时前
ForumLab Review: Fast PHP Script for SEO Forum Sites
android·adb·php
似的8351 天前
一步一步学习使用FireMonkey动画() 使用TAnimator类创建动画
linux·学习·nginx
姜太小白1 天前
【Linux】df -h 卡住问题的通用排查与解决方案总结
linux·运维·php
狗凯之家源码网1 天前
短剧系统搭建实战:源码功能与商业变现效果全景展示
开发语言·php
连续讨伐1 天前
php小结
开发语言·php
2601_965798471 天前
MTDb Movie & TV Database Script Setup, Caching, and SEO Guide
linux·服务器·数据库·php