Tar*_*ula 166
请注意,nginx现在支持版本1.3.13上的Websockets.使用示例:
location /websocket/ {
    proxy_pass ?http://backend_host;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}
您还可以检查nginx更改日志和WebSocket代理文档.
cro*_*ies 53
不用担心,因为一群勇敢的Ops程序员已经通过一个新的nginx_tcp_proxy_module品牌解决了这个问题
写于2012年8月,所以如果你来自未来,你应该做你的功课.
假设您使用的是CentOS:
init.d/nginx脚本)yum install pcre pcre-devel openssl openssl-devel 以及用于构建NGINX的任何其他必要的库再次假设CentOS:
cd /usr/local/wget 'http://nginx.org/download/nginx-1.2.1.tar.gz'tar -xzvf nginx-1.2.1.tar.gzcd nginx-1.2.1/patch -p1 < /path/to/nginx_tcp_proxy_module/tcp.patch./configure --add-module=/path/to/nginx_tcp_proxy_module --with-http_ssl_module (如果需要,可以添加更多模块)makemake install可选的:
sudo /sbin/chkconfig nginx on如果要重新使用它们,请记住先复制旧配置文件.
重要提示:您需要tcp {}在conf中的最高级别创建指令.确保它不在你的http {}指令中.
下面的示例配置显示了单个上游websocket服务器,以及SSL和非SSL两个代理.
tcp {
    upstream websockets {
        ## webbit websocket server in background
        server 127.0.0.1:5501;
        ## server 127.0.0.1:5502; ## add another server if you like!
        check interval=3000 rise=2 fall=5 timeout=1000;
    }   
    server {
        server_name _;
        listen 7070;
        timeout 43200000;
        websocket_connect_timeout 43200000;
        proxy_connect_timeout 43200000;
        so_keepalive on;
        tcp_nodelay on;
        websocket_pass websockets;
        websocket_buffer 1k;
    }
    server {
        server_name _;
        listen 7080;
        ssl on;
        ssl_certificate      /path/to/cert.pem;
        ssl_certificate_key  /path/to/key.key;
        timeout 43200000;
        websocket_connect_timeout 43200000;
        proxy_connect_timeout 43200000;
        so_keepalive on;
        tcp_nodelay on;
        websocket_pass websockets;
        websocket_buffer 1k;
    }
}
Har*_*ood 33
这对我有用:
location / {
    # redirect all HTTP traffic to localhost:8080
    proxy_pass http://localhost:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # WebSocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
- 借鉴:https://github.com/nicokaiser/nginx-websocket-proxy/blob/df67cd92f71bfcb513b343beaa89cb33ab09fb05/simple-wss.conf
小智 16
for .net core 2.0 Nginx with SSL
location / {
    # redirect all HTTP traffic to localhost:8080
    proxy_pass http://localhost:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # WebSocket support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
}
这对我有用
小智 7
对我来说,它归结为proxy_pass位置设置.需要更改http://nodeserverto https://nodeserver,并在节点服务器端设置有效的SSL证书.这样,当我引入外部节点服务器时,我只需要更改IP,其他所有内容都保持相同的配置.
我希望这可以帮助一路上的人......我一直盯着这个问题......叹息......
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
upstream nodeserver {
        server 127.0.0.1:8080;
}
server {
        listen 443 default_server ssl http2;
        listen [::]:443 default_server ssl http2 ipv6only=on;
        server_name mysite.com;
        ssl_certificate ssl/site.crt;
        ssl_certificate_key ssl/site.key;
        location /horizon {
                proxy_pass https://nodeserver;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_intercept_errors on;
                proxy_redirect off;
                proxy_cache_bypass $http_upgrade;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-NginX-Proxy true;
                proxy_ssl_session_reuse off;
            }
}
Pankaj Malhotra撰写的一篇简洁明了的文章讨论了如何使用NGINX进行此操作,可在此处获得。
以下是NGINX的基本配置:
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
upstream appserver {
    server 192.168.100.10:9222; # appserver_ip:ws_port
}
server {
    listen 8888; // client_wss_port
    ssl on;
    ssl_certificate /path/to/crt;
    ssl_certificate_key /path/to/key;
    location / {
        proxy_pass http://appserver;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}
使用 nginx/1.14.0
我有一个在 8097 端口上运行的 websocket 服务器,用户从 8098 端口连接到 wss,nginx 只是解密内容并将其转发到 websocket 服务器
所以我有这个配置文件(就我而言/etc/nginx/conf.d/default.conf)
server {
    listen   8098;
        ssl on;
        ssl_certificate      /etc/ssl/certs/domain.crt;
        ssl_certificate_key  /root/domain.key;
    location / {
        proxy_pass http://hostname:8097;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }
}
| 归档时间: | 
 | 
| 查看次数: | 127866 次 | 
| 最近记录: |