Nginx代理wss

/ Nginx / 没有评论 / 83浏览

后端采用netty搭建WebSocket服务后,不想改动代码支持wss,采用nginx反向代理。

配置

server {
	listen 443;
	server_name localhost;
	ssl on;
	# ssl证书
	ssl_certificate key/xxx.crt;
	ssl_certificate_key key/xxx.key;

	# 代理WebSocket
	location /websocket {
		error_log logs/error.log info;
		proxy_redirect off;
		# 代理的后端ip地址及端口
		proxy_pass http://ip:host/websocket;
		proxy_set_header HOST $host;
		proxy_set_header X-Real_IP $remote_addr;
		proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
	}
}

说明

配置生效:nginx -s reload