Added in basic CORS support. Could do with something to allow customisation of allowed headers though.
This commit is contained in:
parent
7123f31652
commit
496c02ab00
1 changed files with 27 additions and 0 deletions
27
nginx.tmpl
27
nginx.tmpl
|
@ -31,6 +31,11 @@ proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
|
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
|
||||||
|
|
||||||
|
proxy_pass_header Access-Control-Allow-Headers;
|
||||||
|
proxy_pass_header Access-Control-Allow-Methods;
|
||||||
|
proxy_pass_header Access-Control-Allow-Credentials;
|
||||||
|
proxy_pass_header Access-Control-Allow-Origin;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name _; # This is just an invalid value which will never trigger on a real hostname.
|
server_name _; # This is just an invalid value which will never trigger on a real hostname.
|
||||||
|
@ -117,6 +122,17 @@ server {
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass {{ $proto }}://{{ $host }};
|
proxy_pass {{ $proto }}://{{ $host }};
|
||||||
|
|
||||||
|
if ({{"$"}}request_method = 'OPTIONS') {
|
||||||
|
add_header Access-Control-Allow-Origin '{{"$"}}http_origin';
|
||||||
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
|
||||||
|
add_header Access-Control-Allow-Credentials 'true';
|
||||||
|
add_header Access-Control-Allow-Headers 'Origin,Content-Type,Accept';
|
||||||
|
add_header Content-Length 0;
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
|
|
||||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||||
auth_basic "Restricted {{ $host }}";
|
auth_basic "Restricted {{ $host }}";
|
||||||
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
||||||
|
@ -143,6 +159,17 @@ server {
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass {{ $proto }}://{{ $host }};
|
proxy_pass {{ $proto }}://{{ $host }};
|
||||||
|
|
||||||
|
if ({{"$"}}request_method = 'OPTIONS') {
|
||||||
|
add_header Access-Control-Allow-Origin '{{"$"}}http_origin';
|
||||||
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
|
||||||
|
add_header Access-Control-Allow-Credentials 'true';
|
||||||
|
add_header Access-Control-Allow-Headers 'Origin,Content-Type,Accept';
|
||||||
|
add_header Content-Length 0;
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
|
|
||||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||||
auth_basic "Restricted {{ $host }}";
|
auth_basic "Restricted {{ $host }}";
|
||||||
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
||||||
|
|
Loading…
Reference in a new issue