Swarm之Websocket链接慢解决

因为需要前台websocket 链接需要在warm中寻找后台在哪个机子中部署,所以链接很慢。使用nginx代码的方式解决。

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log info;
pid        /var/run/nginx.pid;


events {
    worker_connections  4096;
}


http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        log_format  main  '[$time_local]|$request_time|$remote_addr|"$request"|$status|$body_bytes_sent|"$http_referer"|"$http_host"|"$proxy_add_x_forwarded_for"|"$host"|"$http_user_agent"';

        access_log  /var/log/nginx/access.log  main;

        sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    map $http_upgrade $connection_upgrade {
          default upgrade;
          ''   close;
    }

    server {
        listen 80;
        server_name  localhost;
        client_max_body_size 0;
        #
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        proxy_connect_timeout   60;
        proxy_read_timeout      60;
        proxy_send_timeout      60;    
        proxy_next_upstream error timeout invalid_header;
        
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
                
        location /platform/websocket/rtdata {
            proxy_pass http://platform-manager-svc:8720/rtdata;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}

 

posted @ 2020-10-20 10:23  BeierWu  阅读(673)  评论(0编辑  收藏  举报