nginx转发websocket配置

背景:启动socket后,一般可以用ip进行直连,不过这样会引发很多问题
解决方案:采用 域名+nginx转发

nginx配置如下:

upstream swoole_http_server {
        server 127.0.0.1:9501; # 这里为websocket服务器地址
}

server {
        listen 80;
        server_name xxx.phper520.cn; #这里填自个的域名

        location / {
                #转发地址
				proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   Host      $http_host;
                proxy_set_header   X-NginX-Proxy true;
                proxy_pass         http://swoole_http_server;
				proxy_http_version         1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_redirect off;
		
        }
}

你可能感兴趣的:(nginx,websocket,网络)