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;
}
相关推荐
FfHUCisI16 小时前
GMP 调度器:Go 并发的心脏是如何跳动的
开发语言·golang·php
星云API技术支持17 小时前
企业微信二次开发外部群:群聊数据与联系人信息如何建立关联
数据库·php·企业微信
笑梦无境18 小时前
nginx安装(5)
linux·运维·nginx
墨着染霜华1 天前
SpringCloud Gateway线上Nginx代理后自定义下划线请求头丢失(app_name/app_version获取不到)完美解决
nginx·spring cloud·gateway
流光D1 天前
AI Era: Building Web Sites and Configuring Nginx Reverse Proxy Process
前端·人工智能·nginx
sbjdhjd2 天前
PHP eval 型 RCE:flag 正则过滤与通配符绕过实操 | 01
安全·web安全·网络安全·开源·系统安全·php·网络攻击模型
Lsetea2 天前
Cloudflare报526 Invalid SSL certificate:源站证书与Nginx回源TLS排查
nginx·https·ssl证书·cloudflare·tls
姚不倒2 天前
负载均衡架构设计:F5 ↔ Nginx/HAProxy ↔ Keepalived 全链路映射
运维·网络·nginx
姚不倒2 天前
Tengine 实战:主动健康检查 + 动态 Upstream 配置
运维·网络·nginx
qetfw2 天前
Debian Nginx + PHP-FPM 配置:FastCGI、站点目录与访问验证
linux·nginx·debian·php