diff --git a/server/conf/nginx_vhost.conf.master b/server/conf/nginx_vhost.conf.master
index c9589691a824227e766908f479cf85c8c2d2bf17..3ef9f00dbe0a324437c167b47435415935251f89 100644
--- a/server/conf/nginx_vhost.conf.master
+++ b/server/conf/nginx_vhost.conf.master
@@ -118,7 +118,7 @@ server {
 </tmpl_loop>
 
 <tmpl_loop name="basic_auth_locations">
-        location <tmpl_var name='htpasswd_location'> {
+        location <tmpl_var name='htpasswd_location'> { ##merge##
                 auth_basic "Members Only";
                 auth_basic_user_file <tmpl_var name='htpasswd_path'>.htpasswd;
         }
diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php
index 69cd032e1bcfcfcad1159201ec3b964d43de9a20..ffd5ff7f2e6c4f2a209cb0ef9b531e1bc59a2f7d 100644
--- a/server/plugins-available/nginx_plugin.inc.php
+++ b/server/plugins-available/nginx_plugin.inc.php
@@ -1629,10 +1629,16 @@ class nginx_plugin {
 					}
 					unset($loc_parts);
 					
+					if(!isset($locations[$location]['action'])) $locations[$location]['action'] = 'replace';
+					if(substr($l, -9) == '##merge##'){
+						$locations[$location]['action'] = 'merge';
+					}
+					
 					if(!isset($locations[$location]['open_tag'])) $locations[$location]['open_tag'] = '        location '.$location.' {';
-					if(!isset($locations[$location]['location'])) $locations[$location]['location'] = '';
+					if(!isset($locations[$location]['location']) || $locations[$location]['action'] == 'replace') $locations[$location]['location'] = '';
 					if(!isset($locations[$location]['end_tag'])) $locations[$location]['end_tag'] = '        }';
 					if(!isset($locations[$location]['start_line'])) $locations[$location]['start_line'] = $i;
+
 					unset($lines[$i]);
 					
 				} else {