首页 > Web开发 > 详细

nginx转发处理websocket请求

时间:2020-12-22 16:09:46      阅读:261      评论:0      收藏:0      [点我收藏+]

Nginx nginx.conf

location /v2
{
    try_files /nonexistent @$http_upgrade;
}
location @websocket {
    proxy_redirect off;
    proxy_pass http://127.0.0.1:10000;#代理这个ws链接
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
}
location @ {
    root  /www/wwwroot/xxxxx.xxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
}

OpenResty nginx.conf

location /v2
{
    try_files /nonexistent @$http_upgrade;
}
location @websocket {
    proxy_redirect off;
    proxy_pass http://127.0.0.1:10000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
}
location @ {
    default_type application/json;
    content_by_lua_block {
        ngx.say(‘{"time":‘..os.time()..‘}‘)
    }
}

OpenResty直接透传

location / {
    proxy_pass http://127.0.0.1:10000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_upgrade;
    proxy_set_header Host $http_host;
    content_by_lua_block {
        ngx.say(‘{"time":‘..os.time()..‘}‘)
    }
}

 

nginx转发处理websocket请求

原文:https://www.cnblogs.com/Primzahl/p/14172429.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!