我在做CORS的回應header,location的部份需要用到proxy_pass,但我一直沒辦法順利添加header
nginx設定檔
log_format logdata $Host _ $request_uri | $http_origin | $cors | $pos | $allow_origin _ $allow_methods _ $allow_headers ;
map $http_origin $cors {
'~*^https?://(account\.|asset\.|)dcreater\.com$' 'true';
}
map $cors $allow_origin {
'true' $http_origin;
}
map $cors $allow_methods {
'true' 'GET, OPTIONS, POST';
}
map $cors $allow_headers {
'true' 'User-Agent,Keep-Alive,Content-Type,Pragma,Cache-Control,Upgrade-Insecure-Requests';
}
server {
listen 80;
server_name asset.dcreater.com;
access_log /var/log/nginx/access.log logdata;
error_log /var/log/nginx/error.log;
location / {
if ($request_method = 'OPTIONS') {
return 204;
}
resolver 127.0.0.11;
proxy_pass http://app:8001;
set $pos "71"; # for debug
add_header "Access-Control-Allow-Origin" $allow_origin;
add_header "Access-Control-Allow-Methods" $allow_methods;
add_header "Access-Control-Allow-Headers" $allow_headers;
}
}
log的回應看起來也一切正常
asset.dcreater.com_/static/js/editor.js|http://dcreater.com|true|71|http://dcreater.com_GET, OPTIONS, POST_User-Agent,Keep-Alive,Content-Type,Pragma,Cache-Control,Upgrade-Insecure-Requests
在瀏覽器的回應與請求
感謝