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;
}
相关推荐
大喵桑丶5 小时前
中间件快速部署(Nginx,Keepalived)
运维·nginx·中间件
Chef_Chen6 小时前
数据科学每日总结--Day25--区块链
开发语言·php
chjqxxxx6 小时前
php使用ffmpeg实现视频随机截图并转成图片
ffmpeg·php·音视频
小镇学者6 小时前
【PHP】PHP WebShell(网页木马)分析
android·开发语言·php
come112348 小时前
现代前端技术栈关系详解 (PHP 开发者特供版)
开发语言·前端·php
last demo11 小时前
nfs服务器
linux·运维·服务器·php
q***925112 小时前
PHP搭建开发环境(Windows系统)
开发语言·windows·php
last demo14 小时前
iscsi服务器
linux·运维·服务器·php
q***656915 小时前
Nginx反向代理出现502 Bad Gateway问题的解决方案
运维·nginx·gateway
q***420516 小时前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案
开发语言·redis·php