CORS - Nginx
1 min
server {
server_name _;
listen 80;
access_log /var/log/nginx/access.log vhost;
# add_header Strict-Transport-Security "max-age=31536000" always;
proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header X-Frame-Options;
proxy_hide_header Content-Security-Policy;
#
add_header X-Frame-Options "ALLOWALL";
add_header Content-Security-Policy "frame-ancestors 'self' '<Domínio>'";
server_tokens off;
proxy_cache_bypass $http_upgrade;
client_body_buffer_size 10M;
location / {
add_header Cache-Control no-cache;
expires 0;
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Credentials 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,accept-language';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Credentials 'true' always;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
}