feat(nginx): add cors config
This commit is contained in:
@@ -127,6 +127,35 @@ mkdir -p /var/cache/nginx/proxy_cache
|
||||
|
||||
# create the nginx config file
|
||||
echo "Setting up nginx"
|
||||
cat <<EOF > /etc/nginx/cors.conf
|
||||
if (\$request_method = 'OPTIONS') {
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header 'Access-Control-Allow-Methods' 'HEAD, GET, POST, OPTIONS';
|
||||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
|
||||
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' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
||||
}
|
||||
if (\$request_method = 'GET') {
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
||||
}
|
||||
if (\$request_method = 'HEAD') {
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
||||
}
|
||||
EOF
|
||||
cat <<EOF > /etc/nginx/nginx.conf
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
@@ -207,6 +236,7 @@ http {
|
||||
add_header X-Edge-Cache-Status \$upstream_cache_status;
|
||||
|
||||
location / {
|
||||
include /etc/nginx/cors.conf;
|
||||
$pass_headers
|
||||
proxy_ssl_server_name on;
|
||||
rewrite ^(.*)$ $upstream_base\$1 break;
|
||||
|
||||
Reference in New Issue
Block a user