zoukankan      html  css  js  c++  java
  • centos nginx配置支持WebSocket(signalR)

    signalr 默认会调用websocket去连接集线器,centos下,用nginx默认设置不支持ws的

    所以,必须更改配置,让nginx通过websocket

     server {
        listen 80;
        server_name admin.mu-booking.com; 
        location / {
            proxy_pass http://127.0.0.1:5000; 
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection upgrade;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
        }

    但是,这样问题就来了。ws的服务可以执行了。ajax的请求却不适合,毕竟ws需要的是长连接,ajax的只是短暂的,有返回后连接是会关闭的

    所以,应该设置多个路径

    server {
        listen 80;
        server_name admin.mu-booking.com; 
        location / {
            proxy_pass http://127.0.0.1:5000; 
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection keep-alive;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
        location ~/Hub {
            proxy_pass http://127.0.0.1:5000; 
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection upgrade;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
        }

    关键 

    proxy_set_header Connection upgrade,
    默认key-alive的,改成upgrade

    ~/Hub这个路径,这个对应signalr设置的路径
    
    
  • 相关阅读:
    2020-12
    知识的深度跟知识的广度
    限额类费用报销单N+1原则
    用友实习总结
    NC57,NC63-NC二开经验总结
    union和union all的区别
    2020
    mark_rabbitMQ
    营销之路
    怎么对ORACLE里的CLOB字段进行模糊查询
  • 原文地址:https://www.cnblogs.com/drek_blog/p/10823020.html
Copyright © 2011-2022 走看看