2013-04-05 79 views
2

如何配置nginx(最新版本,他們說它支持websockets)來支持WebSockets。nginx + python + websockets

如何使用python運行websockets連接。

這就是我想要的:

  • 客戶端用JavaScript創建的WebSocket;
  • websocket服務器腳本在python上運行;
  • 和nginx在所有這一切的後端。

身體能幫助我嗎?

回答

2

我快速瀏覽了Nginx的相關changeset,看起來您開始處理websocket請求所需要做的就是在您的nginx配置中設置一個代理。因此,例如:

upstream pythonserver { 
    server localhost:5000; 
} 

server { 
    // normal server config stuff... 

    location /some/uri/here { 
     // Minimum required settings to proxy websocket connections 
     proxy_pass http://pythonserver; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "upgrade"; 

     // Other settings for this location 
    } 
} 

這個小配置片段將代理傳入的WebSocket流量到您的Python應用程序服務器,在本例中假設爲監聽本地連接端口5000

希望這有助於。

+0

謝謝,非常有用。根據'/ some/uri/here','http:// pythonserver',它應該如何查看客戶端和python服務器腳本? – 2013-04-05 14:31:52