diff --git a/vnc_auto.html b/vnc_auto.html
index 064b38997c235be3ed1c6ed110acd5ef2c9c1706..d8eb0a5ad8a0a862b3695131f063224a5e3f2f6b 100644
--- a/vnc_auto.html
+++ b/vnc_auto.html
@@ -122,6 +122,17 @@
             host = WebUtil.getQueryVar('host', window.location.hostname);
             port = WebUtil.getQueryVar('port', window.location.port);
 
+            // if port == 80 (or 443) then it won't be present and should be
+            // set manually
+            if (!port) {
+                if (window.location.protocol.substring(0,4) == 'http') {            
+                    port = 80;
+                }
+                else if (window.location.protocol.substring(0,5) == 'https') {            
+                    port = 443;
+                }
+            }
+
             // If a token variable is passed in, set the parameter in a cookie.
             // This is used by nova-novncproxy.
             token = WebUtil.getQueryVar('token', null);