Skip to content

Instantly share code, notes, and snippets.

@ryuujo1573
Created March 27, 2023 03:39
Show Gist options
  • Save ryuujo1573/4931e98c2726cab7d25af79429577eaa to your computer and use it in GitHub Desktop.
Save ryuujo1573/4931e98c2726cab7d25af79429577eaa to your computer and use it in GitHub Desktop.
use Nginx as Reverse Proxy for WebSocket backends.
# http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream local_origin {
server localhost:5173;
# I was using this for Vite HMR backend.
# For Vite HMR ws proxy, see:
# https://github.com/sapphi-red/vite-setup-catalogue/blob/67b256a796486423caf4cfab396a99c186fcd1ab/examples/with-proxy/vite.config.js#L6-L12
}
server {
listen 80;
# listen 443 ssl;
# ssl_certificate server.crt;
# ssl_certificate_key server.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
location ~ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass http://local_origin;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
}
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment