Nginx跨域
在nginx.conf中配置
upstream pload {
#默认的 策略--轮询策略 RR策略
#权重策略 weight=10;
#ip_hash策略 解决sessin共享问题
#ip_hash;
server localhost:8080 ;#weight=9
#server localhost:8081 ;#weight=1
}
#反向代理服务器
server {
#监听的端口号
listen 80;
#服务器的名称
server_name localhost;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin $http_origin;
location / {
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods $http_access_control_request_method;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers $http_access_control_request_headers;
add_header Access-Control-Max-Age 1728000;
return 204;
}
#转发的服务器的ip地址
proxy_pass http://pload;
}
}
该博客介绍了如何在Nginx服务器上配置跨域策略,通过在nginx.conf中设置upstream和server块,实现对不同端口应用的反向代理,并通过添加特定HTTP头来允许跨域请求。配置包括允许凭证、指定源、处理预检请求等关键步骤。
1080

被折叠的 条评论
为什么被折叠?



