首页 > 解决方案 > Nginx 反向代理不在自定义位置传递标头值

问题描述

这是我nginx.conf在 docker 机器中的文件的反向代理部分:

location / {
    try_files $uri @customer_pwa;
}

location /api {
    try_files $uri @rest_api;
}

location @rest_api {
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_cache_bypass $http_upgrade;
    proxy_pass http://api:7000;
}

但是反向代理不会将我的access_token标头字段传递给嵌套应用程序:

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { cors: true });
  app.setGlobalPrefix('api');
  await app.listen(7000);
}
bootstrap();

标签: nginxnestjsreverse-proxy

解决方案


underscores_in_headers on;

将允许带下划线的标题!


推荐阅读