Skip to content

Instantly share code, notes, and snippets.

@timetocode
Last active June 26, 2019 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timetocode/cc61a30aad270f35ae4f7d12b482ab54 to your computer and use it in GitHub Desktop.
Save timetocode/cc61a30aad270f35ae4f7d12b482ab54 to your computer and use it in GitHub Desktop.
Nginx config and ubuntu systemd services for hosting multiple game instances on ports 8001 through 8005, proxied from urls like wss://subdomain.domain.io/1 through wss://subdomain.domain.io/5; can also remove the ssl and listen on port 80 instead. The service file is an example, but creating 5 called instance1.service through instance5.service a…
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
ssl_certificate /srv/certs/fullchain.pem;
ssl_certificate_key /srv/certs/privkey.pem;
location = /1 {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location = /2 {
proxy_pass http://127.0.0.1:8002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location = /3 {
proxy_pass http://127.0.0.1:8003;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location = /4 {
proxy_pass http://127.0.0.1:8004;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location = /5 {
proxy_pass http://127.0.0.1:8005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# etc if needed
}
[Unit]
Description=instance 1
After=network-online.target
[Service]
Environment=NODE_ENV=production
Type=simple
User=root
WorkingDirectory=/srv
ExecStart=/usr/bin/node ./srv/something.js --port 8001 --url 1
Restart=on-failure
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment