stream {
<!-- 4 instances of a websocket backend at two different registered upstream services -->
upstream wsbackendone {
server 127.0.0.1:2222;
server 127.0.0.1:3333;
}
upstream wsbackendtwo {
server 127.0.0.1:4444;
server 127.0.0.1:5555;
}
}
server {
listen 80;
<!-- this is the only difference between layer 4 and layer 7 -->
location /wsapp {
proxy_pass http://wsbackendone;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /wschat {
proxy_pass http://wsbackendtwo;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}
stream {
<!-- 4 instances of a websocket backend at two different registered upstream services -->
upstream wsbackendone {
server 127.0.0.1:2222;
server 127.0.0.1:3333;
}
upstream wsbackendtwo {
server 127.0.0.1:4444;
server 127.0.0.1:5555;
}
}
server {
listen 80;
location / {
<!-- where index.html "lives" on the server -->
root path/to/indexHtml/directory
}
<!-- this is the only difference between layer 4 and layer 7 -->
location /wsapp {
proxy_pass http://wsbackendone;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /wschat {
proxy_pass http://wsbackendtwo;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}