Nginx配置WebSocket

1)原理
在这里插入图片描述
2)nginx配置

http {
    include       mime.types;
    default_type  application/octet-stream;
	
	# 如果 $http_upgrade 不为 '' (),则 $connection_upgrade 为 upgrade 。
    # 如果 $http_upgrade 为 '' (),则 $connection_upgrade 为 close。
	map $http_upgrade $connection_upgrade{
		default upgrade;
		'' close;
	}

	upstream webservers{
	  server 127.0.0.1:8080 weight=90 ;
	}

    server {
        listen       80;
        server_name  localhost;
        
		# WebSocket
		location /ws/ {
            proxy_pass   http://webservers/ws/;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "$connection_upgrade";
        }
    }
}

相关推荐

  1. nginx配置websocket

    2024-03-12 00:04:05       35 阅读
  2. websocket nignx 配置

    2024-03-12 00:04:05       25 阅读
  3. Nginx Websocket 协议配置支持

    2024-03-12 00:04:05       21 阅读
  4. Nginx配置支持WebSocket功能

    2024-03-12 00:04:05       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-12 00:04:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-12 00:04:05       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-12 00:04:05       82 阅读
  4. Python语言-面向对象

    2024-03-12 00:04:05       91 阅读

热门阅读

  1. Golang 方法的接收器 receiver 指针和值的区别

    2024-03-12 00:04:05       38 阅读
  2. vue知识点杂记

    2024-03-12 00:04:05       41 阅读
  3. 【美团20240309笔试算法题】小美的数组询问

    2024-03-12 00:04:05       43 阅读
  4. 【设计模式】工厂模式与抽象工厂模式

    2024-03-12 00:04:05       42 阅读
  5. FPGA TestBench编写学习

    2024-03-12 00:04:05       42 阅读
  6. Ubuntu 22.04 server 安装GNOME/XFCE/KDE桌面环境

    2024-03-12 00:04:05       44 阅读
  7. JVM相关面试题及常用命令参数

    2024-03-12 00:04:05       45 阅读
  8. 力扣代码学习日记七

    2024-03-12 00:04:05       43 阅读