mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 13:59:02 -04:00
address multiple default_server problem
This commit is contained in:
parent
db315e7113
commit
022f9317a5
2 changed files with 15 additions and 2 deletions
|
|
@ -271,12 +271,19 @@ class NginxConfigurator(common.Installer):
|
|||
def _get_default_vhost(self):
|
||||
vhost_list = self.parser.get_vhosts()
|
||||
# if one has default_server set, return that one
|
||||
default_vhosts = []
|
||||
for vhost in vhost_list:
|
||||
for addr in vhost.addrs:
|
||||
if addr.default:
|
||||
return vhost
|
||||
default_vhosts.append(vhost)
|
||||
|
||||
raise errors.MisconfigurationError("No server blocks found in Nginx configuration.")
|
||||
if len(default_vhosts) == 1:
|
||||
return default_vhosts[0]
|
||||
|
||||
# TODO: present a list of vhosts for user to choose from
|
||||
|
||||
raise errors.MisconfigurationError("Could not automatically find a matching server"
|
||||
" block. Set the `server_name` directive to use the Nginx installer.")
|
||||
|
||||
def _get_ranked_matches(self, target_name):
|
||||
"""Returns a ranked list of vhosts that match target_name.
|
||||
|
|
|
|||
|
|
@ -604,6 +604,12 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
"www.nomatch.com", "example/cert.pem", "example/key.pem",
|
||||
"example/chain.pem", "example/fullchain.pem")
|
||||
|
||||
def test_deploy_no_match_fail_multiple_defaults(self):
|
||||
self.config.version = (1, 3, 1)
|
||||
self.assertRaises(errors.MisconfigurationError, self.config.deploy_cert,
|
||||
"www.nomatch.com", "example/cert.pem", "example/key.pem",
|
||||
"example/chain.pem", "example/fullchain.pem")
|
||||
|
||||
def test_deploy_no_match_add_redirect(self):
|
||||
default_conf = self.config.parser.abs_path('sites-enabled/default')
|
||||
foo_conf = self.config.parser.abs_path('foo.conf')
|
||||
|
|
|
|||
Loading…
Reference in a new issue