Playframework Websocket 的 VHosts Nginx 配置

发布于 2025-01-07 16:53:11 字数 3662 浏览 0 评论 0原文

下面的配置似乎有效,但现在失败了。我按照这篇文章下载并安装 tcp_proxy_module。

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #server {

    #}


    # another virtual host using mix of IP-, name-, and port-based configuration

    server {
        listen       80;
       #listen       locahost:8080;
        server_name  localhost.in;

        location / {
            proxy_pass http://127.0.0.1:9000;
        proxy_set_header        Host            $host;
         }
    }

}

更新:

Nginx 错误日志:

2012/02/21 10:56:59 [error] 14745#0: *278 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerFF HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerFF", host: "test.localhost.in"
2012/02/21 10:56:59 [error] 14745#0: *257 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerChrome HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerChrome", host: "test.localhost.in"
2012/02/21 10:59:40 [error] 15366#0: *10 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerFF HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerFF", host: "test.localhost.in"

更新 2:

使用此配置,我在启动 nginx 时遇到绑定异常。如果我删除 tcp 设置,nginx 就会正常启动。对于常规 http 请求和 WebSocket 请求,我需要端口 80 重定向到 9000

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

tcp {
     upstream websockets {
      ## Play! location
       server 127.0.0.1:9000;
     }   

    server {
        listen 80;
        server_name localhost.in;

        tcp_nodelay on;
        proxy_pass websockets;
   }
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # another virtual host using mix of IP-, name-, and port-based configuration

    server {
        listen       80;
#listen       locahost:8080;
        server_name  localhost.in;

        location / {
            proxy_pass http://127.0.0.1:9000;
        proxy_set_header        Host            $host;
    }
    }

}

The config below seemed to have worked but now its failing. I followed this article to download and install the tcp_proxy_module.

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #server {

    #}


    # another virtual host using mix of IP-, name-, and port-based configuration

    server {
        listen       80;
       #listen       locahost:8080;
        server_name  localhost.in;

        location / {
            proxy_pass http://127.0.0.1:9000;
        proxy_set_header        Host            $host;
         }
    }

}

Update:

Nginx Error Log:

2012/02/21 10:56:59 [error] 14745#0: *278 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerFF HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerFF", host: "test.localhost.in"
2012/02/21 10:56:59 [error] 14745#0: *257 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerChrome HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerChrome", host: "test.localhost.in"
2012/02/21 10:59:40 [error] 15366#0: *10 upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost.in, request: "GET /websocket/room/socket?roomNo=1&user=sameerFF HTTP/1.1", upstream: "http://127.0.0.1:9000/websocket/room/socket?roomNo=1&user=sameerFF", host: "test.localhost.in"

Updated 2:

With this config I get a bind exception when I start nginx. If I remove the tcp settings, nginx comes up alright. I need port 80 to redirect to 9000 for both regular http requests as well as WebSocket requests

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

tcp {
     upstream websockets {
      ## Play! location
       server 127.0.0.1:9000;
     }   

    server {
        listen 80;
        server_name localhost.in;

        tcp_nodelay on;
        proxy_pass websockets;
   }
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # another virtual host using mix of IP-, name-, and port-based configuration

    server {
        listen       80;
#listen       locahost:8080;
        server_name  localhost.in;

        location / {
            proxy_pass http://127.0.0.1:9000;
        proxy_set_header        Host            $host;
    }
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姐不稀罕 2025-01-14 16:53:11

看起来只是 websocket 不起作用。请再次阅读您链接的文章。您没有修改 nginx 配置。

根据该文章,您的示例配置可能如下所示(不过我还没有测试过):

tcp {
    upstream websockets {
        ## Play! location
        server 127.0.0.1:9000;
    }   

    server {
        listen 80;
        server_name localhost.in;

        tcp_nodelay on;
        proxy_pass websockets;
    }
}

It looks like it's just the websockets that are not working. Please read the article you linked again. You did not modify your nginx configuration.

According to that article, a sample configuration for you might look like this (I have not tested it yet, though):

tcp {
    upstream websockets {
        ## Play! location
        server 127.0.0.1:9000;
    }   

    server {
        listen 80;
        server_name localhost.in;

        tcp_nodelay on;
        proxy_pass websockets;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文