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

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

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

	}

}


你可能感兴趣的:(解决问题和分享,nginx,websocket,运维)