時(shí)間:2023-02-07 16:48:01 | 來(lái)源:建站知識(shí)
時(shí)間:2023-02-07 16:48:01 來(lái)源:建站知識(shí)
location /live{ ... add_header 'Access-Control-Allow-Origin' 'http://domain:port' always; add_header 'Access-Control-Allow-Credentials' 'true'; # 為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE'; #為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Headers' '*';}
第一個(gè)響應(yīng)頭是允許跨域的域server { set $cors ''; if ($http_origin ~* "^http://deomain01:port$") { set $cors $http_origin; } if ($http_origin ~* "^http://deomain02:port$") { set $cors $http_origin; } if ($http_origin ~* "^http://deomain002:port$") { set $cors $http_origin; } location /live{ ... add_header 'Access-Control-Allow-Origin' '$cors'; add_header 'Access-Control-Allow-Credentials' 'true'; # 為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE'; #為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Headers' '*'; }
$http_origin這個(gè)格式是nginx取請(qǐng)求中header的XXX的值的。 map $http_origin $cors_list{ default http://aaa.cn; "~ http://bbb.cn" http://bbb.cn; } server { listen 8089; server_name localhost; location /live{ ... add_header 'Access-Control-Allow-Origin' '$cors_list'; add_header 'Access-Control-Allow-Credentials' 'true'; # 為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE'; #為預(yù)檢請(qǐng)求加的header add_header 'Access-Control-Allow-Headers' '*'; }
map指令是ngx_http_map_module模塊提供的,默認(rèn)情況下nginx有加載這個(gè)模塊。關(guān)鍵詞:配置,指定
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。