diff --git a/agent/proxy.py b/agent/proxy.py index 534300f8..5559f810 100644 --- a/agent/proxy.py +++ b/agent/proxy.py @@ -75,12 +75,21 @@ def add_wildcard_hosts(self, wildcards): @job("Add Site to Upstream") def add_site_to_upstream_job(self, upstream, site, skip_reload=False): + self.remove_conflicting_site(site) self.add_site_to_upstream(upstream, site) self.generate_proxy_config() if skip_reload: return self.reload_nginx() + @step("Remove Conflicting Site") + def remove_conflicting_site(self, site): + # Go through all upstreams and remove the site file matching the site name + for upstream in self.upstreams: + conflict = os.path.join(self.upstreams_directory, upstream, site) + if os.path.exists(conflict): + os.remove(conflict) + @step("Add Site File to Upstream Directory") def add_site_to_upstream(self, upstream, site): upstream_directory = os.path.join(self.upstreams_directory, upstream) @@ -147,6 +156,7 @@ def rename_site_on_upstream_job( new_name: str, skip_reload=False, ): + self.remove_conflicting_site(new_name) self.rename_site_on_upstream(upstream, site, new_name) site_host_dir = os.path.join(self.hosts_directory, site) if os.path.exists(site_host_dir):