【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';
		}

	}

}
相关推荐
闲云一鹤2 天前
nginx 快速入门教程 - 写给前端的你
前端·nginx·前端工程化
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
蝎子莱莱爱打怪5 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
何中应5 天前
Nginx转发请求错误
前端·后端·nginx
DianSan_ERP6 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅6 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒6 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
芝士雪豹只抽瑞克五6 天前
Nginx 高性能Web服务器笔记
服务器·nginx
zhangfeng11336 天前
趋动云 如何ssh登录 服务区 项目server
运维·人工智能·ssh