nginx代理websocket

配置如下:

upstream websocket {
        server 10.10.10.203:8889;
}
    
server {
        listen 8888;
        server_name  localhost;
        ssl on;
        ssl_certificate /opt/nginx/certs/certificate.pem;
        ssl_certificate_key /opt/nginx/certs/privatekey.pem;
        ssl_ciphers AES128+EECDH:AES128+EDH;
		
        location / {
		    proxy_pass   http://websocket/;
	   		proxy_http_version 1.1;
	    	proxy_set_header Upgrade $http_upgrade;
	    	proxy_set_header Connection "upgrade";
        }
}

主要是以下3句负责将http升级成websocket:

 	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";

你可能感兴趣的:(websocket,Nginx)