Nginx转发/socket.io请求代理的nodejs服务器

时间:2014-08-25 15:59:39

标签: node.js nginx amazon-ec2 proxy socket.io

我正在尝试将所有/socket.io个请求转发给/broadcaster。这是我的nginx配置:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        access_log /home/ubuntu/logs/broadcaster/access.log;
        error_log /home/ubuntu/logs/broadcaster/error.log;
        root /usr/share/nginx/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        # Enable WS
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;

        location /broadcaster {
                rewrite  ^/broadcaster/(.*)  /$1 break;
                proxy_pass http://127.0.0.1:1337;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
        # simply forward socket.io requests.
        # only one site can run socket.io on this server now
        location /socket.io {
                proxy_pass http://127.0.0.1:1337;
        #       proxy_set_header Upgrade $http_upgrade;
        #       proxy_set_header Connection $connection_upgrade;
        }

}

当我(socket.io)发出GET http://my-ec2-public-dns/socket.io/1/?t=1408981904508之类的请求时,我收到错误400 (Bad Request)
我如何nginx转发/socket.io请求?

0 个答案:

没有答案