cors error docker nginx
Есть сервисы в контейнерах, nginx включительно Фронт расположен отдельно (vue)
с фронта отправляю запрос на http://localhost/auth/profile (axios.withCredentionals: true)
nginx проксирует на auth сервис и ставит следующие заголовки, как указано в конфиге nginx
location /auth {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Credentials' 'true';
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, 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-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, 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;
}
proxy_pass http://auth:3001;
rewrite ^/auth/(.*) /$1 break;
}
получаю ошибку "Cross origin resource sharing error: WildcardOriginNotAllowed" если изменить
add_header 'Access-Control-Allow-Origin' '*' always;
на
add_header 'Access-Control-Allow-Origin' $http_origin always;
получаю ошибку "Cross origin resource sharing error: InvalidAllowCredentionals"
после многих попыток понять, почему эта конфигурация не работает, решил убрать обработку заголовков из nginx, оставить только логику проксирования. Заголовки устанавливаю на nodejs и все работает!
Что я делаю не так в nginx?