From e2ab940ac03ffe4f2cf7c478a1597c0b52f14bc4 Mon Sep 17 00:00:00 2001 From: ohemorange Date: Fri, 20 Oct 2017 16:46:36 -0700 Subject: [PATCH] Fix bug that stopped nginx from finding new server block for redirect (#5198) * fix bug that stopped nginx from finding new server block for redirect * add regression test --- certbot-nginx/certbot_nginx/configurator.py | 5 ++++- certbot-nginx/certbot_nginx/tests/configurator_test.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/certbot-nginx/certbot_nginx/configurator.py b/certbot-nginx/certbot_nginx/configurator.py index 4857942a1..76a7e3eef 100644 --- a/certbot-nginx/certbot_nginx/configurator.py +++ b/certbot-nginx/certbot_nginx/configurator.py @@ -266,7 +266,10 @@ class NginxConfigurator(common.Installer): self.new_vhost.names = set() self.new_vhost.names.add(domain) - name_block = [['\n ', 'server_name', ' ', ' '.join(self.new_vhost.names)]] + name_block = [['\n ', 'server_name']] + for name in self.new_vhost.names: + name_block[0].append(' ') + name_block[0].append(name) self.parser.add_server_directives(self.new_vhost, name_block, replace=True) return self.new_vhost diff --git a/certbot-nginx/certbot_nginx/tests/configurator_test.py b/certbot-nginx/certbot_nginx/tests/configurator_test.py index 4f9f685c2..0028986fa 100644 --- a/certbot-nginx/certbot_nginx/tests/configurator_test.py +++ b/certbot-nginx/certbot_nginx/tests/configurator_test.py @@ -676,6 +676,13 @@ class NginxConfiguratorTest(util.NginxTest): "example/chain.pem", "example/fullchain.pem") + self.config.deploy_cert( + "nomatch.com", + "example/cert.pem", + "example/key.pem", + "example/chain.pem", + "example/fullchain.pem") + self.config.enhance("www.nomatch.com", "redirect") self.config.save()