Amazon ec2 graphql订阅无法连接到elastic beanstalk上的websocket终结点

Amazon ec2 graphql订阅无法连接到elastic beanstalk上的websocket终结点,amazon-ec2,graphql,amazon-elastic-beanstalk,aws-application-load-balancer,graphql-subscriptions,Amazon Ec2,Graphql,Amazon Elastic Beanstalk,Aws Application Load Balancer,Graphql Subscriptions,我有graphql瑜伽(graphql服务器)应用程序,它运行在带有应用程序负载平衡器的Elastic Beanstalk上。我能做查询和变异。但当我尝试使用GraphQL Playerd订阅时,它没有连接到以下错误。 { “错误”:“无法连接到WebSocket终结点。”wss://domainname.com/subscriptions. 请检查终结点URL是否正确。“ } 我检查了应用程序在本地和Heroku dyno中运行良好。 我检查了AWS CloudWatch日志。该请求记录在[0

我有graphql瑜伽(graphql服务器)应用程序,它运行在带有应用程序负载平衡器的Elastic Beanstalk上。我能做查询和变异。但当我尝试使用GraphQL Playerd订阅时,它没有连接到以下错误。 { “错误”:“无法连接到WebSocket终结点。”wss://domainname.com/subscriptions. 请检查终结点URL是否正确。“ }

我检查了应用程序在本地和Heroku dyno中运行良好。
我检查了AWS CloudWatch日志。该请求记录在[0mGET/subscriptions[330404[0m3.860 ms-152[0m

中。我实际上也遇到了同样的问题,发现它与服务器端口的启动方式以及我在FE上配置Apollo Provider的方式有关。注意“ws”不起作用,需要“wss”我没有像你使用“/subscriptions”那样将任何内容定向到特定的url。相反,我只使用Heroku/localhost提供给我的URI

服务器图形QLServer代码:

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  context: { pubsub, endpoint: "/" },
});
server.start(({ port }) => {
  console.log(`Server listening on ${port} for incoming requests`);
});
服务器启动代码:

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  context: { pubsub, endpoint: "/" },
});
server.start(({ port }) => {
  console.log(`Server listening on ${port} for incoming requests`);
});
FE阿波罗提供商配置

const httpLink = new HttpLink({
  uri: "https://domainName.herokuapp.com,
});

const wsLink = new WebSocketLink({
  uri: "wss://domainName.herokuapp.com/",
  options: {
    reconnect: true,
  },
});

const splitLink = split(
  ({ query }) => {
    const definition = getMainDefinition(query);
    return (
      definition.kind === "OperationDefinition" &&
      definition.operation === "subscription"
    );
  },
  wsLink,
  httpLink
);

const client = new ApolloClient({
  link: splitLink,
  uri: "https://domainName.herokuapp.com",
  cache: new InMemoryCache({
    addTypename: false,
  }),
});

希望这能帮你解决问题,让你继续前进。我花了半天时间来了解我自己。我想对你来说可能是同样的情况,只是对你的情况有点不同。祝你编码愉快!!!

我已经了解到带有Elastic Beanstalk的EC2实例有一个默认的Nginx配置。 我已经用手动更改了nginx.conf

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
它成功了