signalr 默認會調用websocket去鏈接集線器,centos下,用nginx默認設置不支持ws的nginx
因此,必須更改配置,讓nginx經過websocketweb
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的只是短暫的,有返回後鏈接是會關閉的ajax
因此,應該設置多個路徑centos
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; } }
關鍵 websocket
proxy_set_header Connection upgrade,默認key-alive的,改爲upgrade~/Hub這個路徑,這個對應signalr設置的路徑