Last active
November 18, 2021 00:11
-
-
Save alexishida/62427dea9353a4da6368eec268e794bf to your computer and use it in GitHub Desktop.
Configuring nginx as a proxy / load balancer (HTTP and Websocket connections)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://deepstreamhub.com/blog/load-balancing-websocket-connections | |
| # https://deepstreamhub.com/open-source/integrations/other-nginx | |
| # Websocket | |
| # proxy_http_version 1.1; | |
| # proxy_set_header Upgrade $http_upgrade; | |
| # proxy_set_header Connection "upgrade"; | |
| # proxy_set_header Connection $http_connection; | |
| worker_processes 1; | |
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| map $http_upgrade $connection_upgrade { | |
| default upgrade; | |
| '' close; | |
| } | |
| upstream websocket { | |
| server localhost:6020; | |
| } | |
| upstream httpendpoint { | |
| server localhost:8080; | |
| } | |
| server { | |
| listen 9090; | |
| # Deepstream websocket redirect | |
| location /deepstream { | |
| proxy_pass http://websocket; | |
| proxy_http_version 1.1; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "upgrade"; | |
| proxy_set_header Connection $http_connection; | |
| rewrite ^/deepstream(.*) $1 break; | |
| } | |
| # Deepstream http endpoint | |
| location /http { | |
| proxy_pass http://httpendpoint; | |
| proxy_http_version 1.1; | |
| rewrite ^/http(.*) $1 break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment