nginx跨域配置

本文详细解析了Nginx反向代理的配置方法,包括如何设置代理服务器、跨域请求处理、请求超时时间和头部信息传递等关键参数。通过具体的配置示例,帮助读者理解Nginx在实现负载均衡、提升网站性能和安全性方面的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

location /{
	proxy_pass http://127.0.0.1:8080/;
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_connect_timeout 90;
	# add_header Access-Control-Allow-Origin "*";
	add_header Access-Control-Allow-Origin "$http_origin";
	add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
	add_header Access-Control-Allow-Credentials 'true';
	add_header Access-Control-Allow-Headers 'Accept,token, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
	if ($request_method = 'OPTIONS') {
		add_header 'Access-Control-Allow-Origin' "$http_origin";
		add_header 'Access-Control-Max-Age' 1728000;
		add_header 'Access-Control-Allow-Credentials' 'true';
		add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS';
		add_header 'Access-Control-Allow-Headers' 'Accept,token,Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
		return 200;
	}

 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值