Skip to content

Instantly share code, notes, and snippets.

@alexblom
Last active August 8, 2019 03:13
Show Gist options
  • Save alexblom/98669900f9784eac1262 to your computer and use it in GitHub Desktop.
Save alexblom/98669900f9784eac1262 to your computer and use it in GitHub Desktop.
Golang Websocket Nginx
#Golang Websocket Server
server {
listen 8080;
server_name wss.morse.io;
access_log /var/log/nginx/access_log.log;
error_log /var/log/nginx/error.log;
#ssl config
ssl on;
#Cert Info
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
proxy_read_timeout 300s;
location /goServer {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:8081/goServer;
}
}
@steveoc64
Copy link

Hi Alex,

Did you ever have any success with this ?

I have been trying different combos of settings in nginx to get it to handle WS connections to my golang backends, but no luck for me :(

I am getting the golang process to receive the upgrade request, which it returns a http.StatusOK on, but the client only gets an error. Was thinking it might be something specific to the http wrapper libs I am using on the go backend. Dont know.

I am using labstack/echo for my http serving needs.

Would love to hear how you went getting websockets working through nginx to a golang backend.

Cheers

@nteissler
Copy link

Just ran into this same issue. The post here solved my problems with nothing but a copy and paste. I'm looking into what all the settings mean now.

http://stackoverflow.com/questions/22091351/unable-to-get-go-net-websocket-working-behind-nginx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment