-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnginx-cors-proxy.conf
61 lines (50 loc) · 2.15 KB
/
nginx-cors-proxy.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
upstream backend {
server $BACKEND;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
underscores_in_headers on;
server_name cors;
location / {
proxy_pass http://backend;
proxy_redirect http://$BACKEND http://$http_host;
proxy_read_timeout 300;
client_max_body_size 500M;
proxy_set_header Proxy '';
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_set_header X-Forwarded-Proto $scheme;
proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header Access-Control-Allow-Credentials;
set $CORS_CREDS true;
set $CORS_ORIGIN $http_origin;
set $CORS_METHODS 'GET, POST, PUT, DELETE, OPTIONS';
set $CORS_HEADERS 'Authentication-Token, Cache-Control, Cookie, If-Modified-Since, Range, User-Agent, X-Requested-With';
# FYI: Always allowed headers: Accept, Accept-Language, Content-Language, Content-Type
set $CORS_EXPOSE_HEADERS 'Content-Disposition, Content-Length, Content-Range, Set-Cookie';
# FYI: Always exposed headers: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma
set $CORS_PREFLIGHT_CACHE_AGE 600;
set $X_FRAME_OPTIONS '';
# set $X_FRAME_OPTIONS "ALLOW FROM $http_origin";
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $CORS_ORIGIN;
add_header Access-Control-Allow-Methods $CORS_METHODS;
add_header Access-Control-Allow-Headers $CORS_HEADERS;
add_header Access-Control-Allow-Credentials $CORS_CREDS;
add_header Access-Control-Max-Age $CORS_PREFLIGHT_CACHE_AGE;
add_header Content-Type 'text/plain; charset=utf-8';
add_header Content-Length 0;
return 204;
}
if ($request_method != 'OPTIONS') {
add_header Access-Control-Allow-Origin $CORS_ORIGIN;
add_header Access-Control-Allow-Methods $CORS_METHODS;
add_header Access-Control-Allow-Headers $CORS_HEADERS;
add_header Access-Control-Allow-Credentials $CORS_CREDS;
add_header Access-Control-Expose-Headers $CORS_EXPOSE_HEADERS;
add_header X-Frame-Options $X_FRAME_OPTIONS;
}
}
}