Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询参数nginx的条件上游_Nginx_Socket.io_Cluster Computing - Fatal编程技术网

查询参数nginx的条件上游

查询参数nginx的条件上游,nginx,socket.io,cluster-computing,Nginx,Socket.io,Cluster Computing,我有两组接收websocket()连接的应用程序。示例uri字符串可能是 http://myurl.com/socket.io/?EIO=3&transport=polling&t=1435096473367-0&b64=1&type=device 我需要让查询参数为/valuetype=device的所有请求使用一个上游路由,所有其他请求转到另一个上游 在#nginx irc中,我被告知使用if是解析查询参数的最佳方式,因此我想到了以下方法: user www

我有两组接收websocket()连接的应用程序。示例uri字符串可能是

http://myurl.com/socket.io/?EIO=3&transport=polling&t=1435096473367-0&b64=1&type=device
我需要让查询参数为/value
type=device
的所有请求使用一个上游路由,所有其他请求转到另一个上游

在#nginx irc中,我被告知使用
if
是解析查询参数的最佳方式,因此我想到了以下方法:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
  worker_connections 768;
  # multi_accept on;
}

http {
  ##
  # Basic Settings
  ##

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  include /opt/nginx/conf/mime.types;
  default_type application/octet-stream;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  ##
  # My settings
  ##

  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
  proxy_temp_path /var/tmp;

  upstream normal_upstream {
    least_conn;
    server 127.0.0.1:9000 fail_timeout=20s;
    #server 127.0.0.1:9001 fail_timeout=20s;
    #server 127.0.0.1:9002 fail_timeout=20s;
    #server 127.0.0.1:9003 fail_timeout=20s;
  }

  upstream device_upstream {
    least_conn;
    server 127.0.0.1:8000 fail_timeout=20s;
    #server 127.0.0.1:8001 fail_timeout=20s;
    #server 127.0.0.1:8002 fail_timeout=20s;
    #server 127.0.0.1:8003 fail_timeout=20s;
  }

  server {
    client_max_body_size 10m;

    listen 443 ssl;
    ssl_certificate /root/ssl/bundle.crt;
    ssl_certificate_key /root/ssl/myurl.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;

    server_name myurl.com www.myurl.com;

    location / {
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;

      set $upstream $normal_upstream;
      if($arg_type = device){
        set $upstream $device_upstream;
      }

      proxy_pass https://$upstream;      
    } 
  }
}
简言之,我正在使用

set $upstream $my_upstream;
if ( $arg_type = device ){
  $upstream $device_upstream;
}
proxy_pass http://$upstream;
基本上,上游将根据arg_类型是否设置为device或留空而改变。我相信这会奏效,但我不确定这是否是解决我问题的正确方法