使用websockets在弹性beanstalk上扩展nginx

时间:2017-11-14 19:03:32

标签: node.js amazon-web-services nginx elastic-beanstalk

我想设置一个弹性beanstalk应用程序来处理HTTP和Websockets。我可以在端口8081上运行HTTP,但我无法访问我的websocket服务器,因为我的nginx出现301重定向错误。我可以告诉我的websocket服务器正在运行,有谁知道为什么我无法访问它?这是我的proxy.config文件:

  upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
  }

  upstream wsserver {
    server 127.0.0.1:3000;
    keepalive 256;
  }

  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;

    # prevents 502 bad gateway error
    large_client_header_buffers 8 32k;

    location /ws/ {
        # prevents 502 bad gateway error
        proxy_buffers 8 32k;
        proxy_buffer_size 64k;
        proxy_pass http://wsserver;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;

    }

    location / {
        proxy_pass  http://nodejs;
        proxy_set_header   Connection "";
        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;
    }
    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;
  }

0 个答案:

没有答案