可执行命令 sudo certbox --nginx 后。 Certbot 给我输出
Saving debug log to /var/log/letsencrypt/letsencrypt.log
An unexpected error occurred:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 10453: ordinal not in range(128)
Please see the logfiles in /var/log/letsencrypt for more details.
这是最后一个日志文件
2018-07-31 14:43:08,904:DEBUG:certbot.main:certbot version: 0.25.1
2018-07-31 14:43:08,905:DEBUG:certbot.main:Arguments: ['--nginx']
2018-07-31 14:43:08,906:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#nginx,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2018-07-31 14:43:08,918:DEBUG:certbot.log:Root logging level set at 20
2018-07-31 14:43:08,919:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2018-07-31 14:43:08,920:DEBUG:certbot.plugins.selection:Requested authenticator nginx and installer nginx
2018-07-31 14:43:08,967:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/bin/certbot", line 11, in <module>
load_entry_point('certbot==0.25.1', 'console_scripts', 'certbot')()
File "/usr/lib/python3.6/site-packages/certbot/main.py", line 1323, in main
return config.func(config, plugins)
File "/usr/lib/python3.6/site-packages/certbot/main.py", line 1073, in run
installer, authenticator = plug_sel.choose_configurator_plugins(config, plugins, "run")
File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 195, in choose_configurator_plugins
authenticator = installer = pick_configurator(config, req_inst, plugins)
File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 25, in pick_configurator
(interfaces.IAuthenticator, interfaces.IInstaller))
File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 77, in pick_plugin
verified.prepare()
File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 246, in prepare
return [plugin_ep.prepare() for plugin_ep in six.itervalues(self._plugins)]
File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 246, in <listcomp>
return [plugin_ep.prepare() for plugin_ep in six.itervalues(self._plugins)]
File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 127, in prepare
self._initialized.prepare()
File "/usr/lib/python3.6/site-packages/certbot_nginx/configurator.py", line 144, in prepare
self.parser = parser.NginxParser(self.conf('server-root'))
File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 38, in __init__
self.load()
File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 45, in load
self._parse_recursively(self.config_root)
File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 66, in _parse_recursively
self._parse_recursively(subentry[1])
File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 56, in _parse_recursively
trees = self._parse_files(filepath)
File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 207, in _parse_files
parsed = nginxparser.load(_file)
File "/usr/lib/python3.6/site-packages/certbot_nginx/nginxparser.py", line 123, in load
return loads(_file.read())
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 10453: ordinal not in range(128)
2018-07-31 14:43:08,969:ERROR:certbot.log:An unexpected error occurred:
呃,我用Arch。
答案1
当我上次遇到这个问题时,LetsEncrypt 正在尝试读取默认 nginx 配置中的非 ASCII 字符,以便它可以添加自己的配置。以下命令对于查找所有非 ASCII 字符很有用(需要 GNU grep
)-P
:
grep -Rn --color='auto' -P "[\x80-\xFF]" /etc/nginx
具体来说,请仔细查看 /etc/nginx/sites-enabled/default。在我刚刚检查的系统上,第 29 行的注释以 开头# ssl_protocols
,并且该行包含非 ASCII 字符(应该是该行“don't”中的撇号),这阻碍了 LetsEncrypt 设置。
您可以从该文件中删除这些字符或禁用默认配置。一旦它不在主 nginx 配置中,LetsEncrypt 就不会再出现该错误。
答案2
听起来好像您的 nginx 文件之一中有一个 certbot 无法读取的随机字符。文件上的字符编码可能与输入到文档中的字符不匹配。或者损坏的 nginx 文件。
检查 中列出的所有虚拟服务器文件/etc/nginx/conf.d/
。使用纯文本编辑器重新创建每个文件,并使用使用的/预期的编码保存文件。