【nginx】nginx部署升级htpp+websocket访问

关注todo-step1和todo-step2就行了:

js 复制代码
user root;
......
http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	types_hash_max_size 2048;
	

	client_max_body_size 10240m;
	include /etc/nginx/mime.types;
	default_type application/octet-stream;

    # 配置websocket访问 *****************todo-step:1*****************
    map $http_upgrade $connection_upgrade { 
        default          keep-alive;  #默认为keep-alive 可以支持 一般http请求
        'websocket'      upgrade;     #如果为websocket 则为 upgrade 可升级的。
    }

	# 配置80访问gateway
	upstream gateway{
	server com.xxx.com:30000;
	}

	server {

		listen 80; # 监听端口
		server_name com.xxx.com; #配置域名或IP地址

		location / {
			proxy_pass  http://gateway/; # 将请求转发到backend_server服务器的地址
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的 *****************todo-step:2*****************
			proxy_set_header Connection $connection_upgrade;
		}

		location /xx/ {
			alias /xx/temp/; # 将请求转发到服务器的地址
			add_header Front-End-Https on;
			add_header 'Access-Control-Allow-Headers' '*';
			add_header 'Access-Control-Allow-Methods' '*';
			add_header 'Access-Control-Allow-Origin' $http_origin;
			add_header 'Access-Control-Allow-Credentials' 'true';
		}

	}

}
相关推荐
阿里云大数据AI技术5 分钟前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
小猿姐2 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
SkyWalking中文站2 天前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维
SkyWalking中文站3 天前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
雪梨酱QAQ3 天前
Kubeneters HA Cluster部署
运维
江华森3 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森3 天前
Matplotlib 数据绘图基础入门
运维
江华森3 天前
NumPy 数值计算基础入门
运维