joequery
11/12/2015 - 6:28 PM

VM Port forwarding config

VM Port forwarding config

#########################
# On host
#########################
server{
    auth_basic "Restricted";
    auth_basic_user_file /path/to/authfile;
    server_name "~^8(?<theport>\d{3})\.vm\.domain\.com$";
    location / {
        set $baseport "8";
        set $fullport $baseport$theport;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host       $http_host;
        proxy_set_header Vmport       $fullport;
        proxy_pass http://10.50.50.50; # private IP of VM
    }
}

#########################
# On guest
#########################
server{
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host       $http_host;
        proxy_pass http://127.0.0.1:$http_vmport;
    }
}