【问题标题】:nginx as a proxy for Websocket to send text messagesnginx作为Websocket的代理发送短信
【发布时间】:2014-08-08 14:07:36
【问题描述】:

我有一个在 vm 上运行的 websocket 服务(远程地址端口 8090)。使用 Nginx 代理连接。 nginx配置如下:

server {
    listen 80;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_pass_request_headers on;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
}

从我的本地主机,我能够使用 ip 作为ws://111.11.1.1/websocket 连接到 websocket

但是,当我从本地主机或应用程序向远程 websocket websocket.sendTextMessage("Message") 发送消息时,我无法访问套接字..假设我的 nginx 配置有问题..

更新:通过添加更改 Nginx 的配置

http{ server{..location/{...}}}

当我重新启动 Nginx 服务时,我得到一个错误

nginx emerg http directive is not allowed here in /default.conf:1

nginx: configuration file /nginx.conf test failed

任何建议都有帮助!

【问题讨论】:

    标签: java nginx websocket


    【解决方案1】:

    使用以下配置,它可能会有所帮助。

    server {
    
    listen 80;
    server_name _;
    location / {
    
            proxy_pass http://127.0.0.1:8090;
            proxy_redirect off;
            proxy_pass_request_headers on;
    
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection Upgrade;
    
        }
    

    }

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      相关资源
      最近更新 更多