Skip to content

Fix CORS config #1649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions pkg/workloads/cortex/serve/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,38 @@ http {
}

location ~ ^/(predict/?|)$ {
limit_conn inflights {{ CORTEX_MAX_REPLICA_CONCURRENCY | int }};
# CORS (inspired by https://enable-cors.org/server_nginx.html)
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}

add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Headers "*";
add_header Access-Control-Allow-Methods "GET, POST";
add_header Access-Control-Allow-Credentials "true";
limit_conn inflights {{ CORTEX_MAX_REPLICA_CONCURRENCY | int }};

proxy_set_header HOST $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header 'HOST' $host;
proxy_set_header 'X-Forwarded-For' $proxy_add_x_forwarded_for;
proxy_set_header 'X-Real-IP' $remote_addr;
proxy_set_header 'X-Forwarded-Proto' $scheme;

proxy_redirect off;
proxy_buffering off;
Expand Down