study memo

nginx cors ์„ค์ • ์ฝ”๋“œ ์ €์žฅ์šฉ

sebarii 2024. 7. 26. 16:02
location /api/ {

        if ($request_method = 'OPTIONS') {
         add_header 'Access-Control-Allow-Origin' $allowed_origin always;
         add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PATCH, OPTIONS';
         add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
         add_header 'Access-Control-Allow-Credentials' 'true';
         return 204;
        }

        #rewrite ^/api(.*)$ $1 break;
        proxy_pass http://localhost:3010;
        proxy_hide_header Access-Control-Allow-Origin;
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Origin' $allowed_origin always;
        proxy_http_version 1.1;
        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;
    }