Repository: certbot/certbot

Issue:
Nginx plugin not able to get version number from openresty nginx binary
## My operating system is (include version):
Ubuntu 16.04

## I installed Certbot with (certbot-auto, OS package manager, pip, etc):
certbot-auto

## I ran this command and it produced this output:
`certbot-auto certonly --nginx`
```
Error: invalid literal for int() with base 10: ''
```
This is because in the nginx configurator code:
https://github.com/certbot/certbot/blob/master/certbot-nginx/certbot_nginx/configurator.py#L649

it uses regex `version_regex = re.compile(r"nginx/([0-9\.]*)", re.IGNORECASE)` but the version number of openresty nginx is like `nginx version: openresty/1.11.2.2`


## Certbot's behavior differed from what I expected because:
nginx plugin should support openresty or prompt it doesn't support




Discussion:
This seems like something @ohemorange should know about
Also thanks for the super thorough bug report!
Copied from https://github.com/certbot/certbot/pull/4833#issuecomment-316228804:

I think the best thing to do here is to leave the regex as is and do the existing check if we find matches. But if we don't find a version string matching the official version format, we should print a warning saying that we don't officially support forks of Nginx, and continue. This is different from what we do now in that we currently error out if we can't find a version string.

@ohemorange Yeah for me both way works (fix or warning message instead of error)
but on the other hand, since some of the forks like tenginex and openresty are widely used, if certbot could support them, it will help more websites move to https, what do you think?
We will "support" them by not automatically breaking when we encounter them. Guaranteeing that we'll handle all bugs that are caused by using them instead of the standard version is a much larger burden.

Resolving patch:
diff --git a/certbot-nginx/certbot_nginx/configurator.py b/certbot-nginx/certbot_nginx/configurator.py
--- a/certbot-nginx/certbot_nginx/configurator.py
+++ b/certbot-nginx/certbot_nginx/configurator.py
@@ -748,7 +748,7 @@ def get_version(self):
             raise errors.PluginError(
                 "Unable to run %s -V" % self.conf('ctl'))
 
-        version_regex = re.compile(r"nginx/([0-9\.]*)", re.IGNORECASE)
+        version_regex = re.compile(r"nginx version: ([^/]+)/([0-9\.]*)", re.IGNORECASE)
         version_matches = version_regex.findall(text)
 
         sni_regex = re.compile(r"TLS SNI support enabled", re.IGNORECASE)
@@ -765,7 +765,12 @@ def get_version(self):
         if not sni_matches:
             raise errors.PluginError("Nginx build doesn't support SNI")
 
-        nginx_version = tuple([int(i) for i in version_matches[0].split(".")])
+        product_name, product_version = version_matches[0]
+        if product_name is not 'nginx':
+            logger.warning("NGINX derivative %s is not officially supported by"
+                           " certbot", product_name)
+
+        nginx_version = tuple([int(i) for i in product_version.split(".")])
 
         # nginx < 0.8.48 uses machine hostname as default server_name instead of
         # the empty string


Test patch: