【问题标题】:Configuring Secure Web Socket on Amazon Beanstalk在 Amazon Beanstalk 上配置安全 Web 套接字
【发布时间】:2018-08-07 06:55:14
【问题描述】:

我在 Amazon Beanstalk 上部署了两个 Node.js 应用程序:一个是使用 React 开发并使用 serve 运行的前端,另一个是带有 Web 套接字处理程序的 an MQTT broker。 负载均衡器是 nginx 1.12.1,配置如下(写在后端项目的.ebextension 文件夹内):

  map $http_upgrade $connection_upgrade {
      default upgrade;
      '' close;
  }

  upstream websocket {
      server 127.0.0.1:5000;
  }

  server {
    listen 8080;

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
        set $year $1;
        set $month $2;
        set $day $3;
        set $hour $4;
    }
    access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
    access_log  /var/log/nginx/access.log  main;
    large_client_header_buffers 8 32k;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass  "http://127.0.0.1:3003";

        proxy_redirect off;

        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass_request_headers      on;
    }

    location /subscriptions {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    gzip on;
    gzip_comp_level 4;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  }

前端应该能够使用wss://mqtt_url/subscriptions,但是无论我使用什么配置,我总是得到WebSocket is closed before the connection is established。此配置似乎适用于非安全 Web 套接字消费。 等待连接的服务器只是一个简单的 HTTP 服务器,如下所示:

const server = createServer();

server.listen(5000, '0.0.0.0', () =>
  new SubscriptionServer({
        execute,
        subscribe,
        schema,
        onConnect: async (connectionParams) => {

        },
  }, {
        server,
        path: '/subscriptions',
  }));

Beanstalk 负载均衡配置如下:

  • 端口:80 端口上的 TCP
  • 端口:80
  • 安全端口:端口 443 上的 SSL 安全
  • 端口:443
  • 健康状况:端口 80 上的 TCP ping
  • 已启用跨区域负载平衡
  • 使用 200 秒超时启用连接耗尽

四处搜索,我发现选择TCP/SSL作为协议很好,但除此之外,这里如何配置WSS并不是很清楚。 任何建议将不胜感激! 谢谢。

【问题讨论】:

    标签: nginx websocket amazon-elastic-beanstalk


    【解决方案1】:

    尝试将此添加到您的订阅位置块

    proxy_read_timeout 86400;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-24
      • 2019-01-13
      • 2015-02-23
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      相关资源
      最近更新 更多