upstream webservers {
    server web:5000 weight=1;
}

server {
    listen       80;

    location / {
        root /data/web/; # 前端代码
        try_files $uri $uri/ /index.html;
        add_header access-control-allow-origin *;
    }

    location ^~ /api/ {
        add_header        access-control-allow-origin *;
        proxy_pass        http://webservers;
        proxy_set_header  X-Forwarded-Host $host:$server_port;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  Origin        $host:$server_port;
        proxy_set_header  Referer       $host:$server_port;
    }

    location ^~ /socket.io/ {
        add_header        access-control-allow-origin *;
        proxy_pass        http://webservers;
        proxy_set_header  X-Forwarded-Host $host:$server_port;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  Origin        $host:$server_port;
        proxy_set_header  Referer       $host:$server_port;
        proxy_set_header  Host $http_host;
        proxy_set_header  X-NginX-Proxy true;

        # WebScoket Support
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
    }

}
