diff --git a/nginx/templates/nginx-virthost.j2 b/nginx/templates/nginx-virthost.j2
index 48ff98b5..5c3b0c77 100644
--- a/nginx/templates/nginx-virthost.j2
+++ b/nginx/templates/nginx-virthost.j2
@@ -194,10 +194,6 @@ server {
     {% endfor %}
     {% endif %}
 
-    {% if item.websockets is defined and item.websockets %}
-    proxy_set_header Upgrade $http_upgrade;
-    proxy_set_header Connection $connection_upgrade;
-    {% endif %}
     {% if item.proxy_standard_setup is defined and item.proxy_standard_setup %}
     # Proxy stuff
     {% if item.include_global_proxy_conf is defined and not item.include_global_proxy_conf %}
@@ -222,6 +218,10 @@ server {
         {% if location.target is defined %}
 		proxy_pass {{ location.target }};
         {% endif %}
+        {% if location.websockets is defined and location.websockets %}
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "Upgrade";
+        {% endif %}
         {% if location.extra_conf is defined %}
         {{ location.extra_conf }}
         {% endif %}