Skip to content

Instantly share code, notes, and snippets.

@mabuak
Created June 28, 2018 08:46
Show Gist options
  • Save mabuak/1205247bcb1ffb4b91b131e30194d9fe to your computer and use it in GitHub Desktop.
Save mabuak/1205247bcb1ffb4b91b131e30194d9fe to your computer and use it in GitHub Desktop.
websocket nginx configuration
# Install SSL Certificate
openssl req -x509 -out imessage.loc.crt -keyout imessage.loc.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=imessage.loc' -extensions EXT -config <( \
printf "[dn]\nCN=imessage.loc\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:imessage.loc\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
# Copy paste this nginx configuration
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server imessage.loc:5300;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/conf.d/imessage.loc.crt;
ssl_certificate_key /etc/nginx/conf.d/imessage.loc.key;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment