# BUG! init\_by\_lua\_block and certbot

**URL:** <https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952>\
**Category:** Help\
**Created:** [October 12, 2021, 10:26pm UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952 "2021-10-12T22:26:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![slava1](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@slava1](https://community.letsencrypt.org/u/slava1)\
**Post date:** [October 12, 2021, 10:26pm UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/1 "2021-10-12T22:26:26Z")

</div>

Using [GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers](https://github.com/openresty/lua-nginx-module) I can't use certbot.

sudo certbot --nginx

> Saving debug log to /var/log/letsencrypt/letsencrypt.log  
> Could not parse file: /etc/nginx/nginx.conf due to Expected stringEnd, found 'h' (at char 79), (line:9, col:1)  
> Please enter the domain name(s) you would like on your certificate (comma and/or  
> space separated) (Enter 'c' to cancel): ^CExiting due to user request.

```nohighlight
lua_package_path "./lua/?.lua;/etc/nginx/lua/?.lua;/path/to/lua-resty-core/lib/?.lua;;";

	init_by_lua_block {
		require "resty.core"
		collectgarbage("collect") -- just to collect any garbage
	}

```

Due to the script can't parse 'lua code'.  
What should I do? This module is popular.

---

<div class="post-metadata">

**Author:** ![rg305](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/rg305/32/91314_2.png) [@rg305](https://community.letsencrypt.org/u/rg305)\
**Post date:** [October 12, 2021, 10:49pm UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/2 "2021-10-12T22:49:25Z")

</div>

Hi @slava1 and welcome to the LE community forum 🙂

> [@slava1](#):
>
> What should I do?

Let's start with:

> [@slava1](#):
>
> line:9

of file:

> [@slava1](#):
>
> /etc/nginx/nginx.conf

---

<div class="post-metadata">

**Author:** ![slava1](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@slava1](https://community.letsencrypt.org/u/slava1)\
**Post date:** [October 13, 2021, 6:42am UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/3 "2021-10-13T06:42:25Z")

</div>

```nohighlight

error_log stderr notice;
#daemon off;

events {
  worker_connections 1024;
}

http { # line9
	
	include mime.types;

	lua_code_cache off;
	lua_package_path "./lua/?.lua;/etc/nginx/lua/?.lua;/path/to/nginx/lua-resty-core/lib/?.lua;;";

	init_by_lua_block {
		require "resty.core" # certbot crashes when I add this line and the next line
		collectgarbage("collect") -- just to collect any garbage # these lines can be written in lua code
	}
server { ..... } # no problem here

}

```

line 9 is `http`

```nohighlight

error_log stderr notice;
#daemon off;

events {
  worker_connections 1024;
}

http { # line9
	
	include mime.types;

	lua_code_cache off;
	lua_package_path "./lua/?.lua;/etc/nginx/lua/?.lua;/path/to/nginx/lua-resty-core/lib/?.lua;;";

	init_by_lua_block {
	}
server { ..... } # no problem here

}

```

---

<div class="post-metadata">

**Author:** ![orangepizza](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/orangepizza/32/19597_2.png) [@orangepizza](https://community.letsencrypt.org/u/orangepizza)\
**Post date:** [October 13, 2021, 7:07am UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/4 "2021-10-13T07:07:36Z")

</div>

looks like it certbot parser is broken: [@certbot-devs](https://community.letsencrypt.org/groups/certbot-devs) could you look at this?  
while, could you use webroot auth to get at certificate, skiping certbot's nginx parser?

---

<div class="post-metadata">

**Author:** ![\_az](https://avatars.discourse-cdn.com/v4/letter/_/22d042/32.png) [@\_az](https://community.letsencrypt.org/u/_az)\
**Post date:** [October 13, 2021, 9:03am UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/6 "2021-10-13T09:03:59Z")

</div>

> [@orangepizza](#):
>
> while, could you use webroot auth to get at certificate, skiping certbot's nginx parser?

Yes, I think @slava1 will need to use `certbot certonly --webroot` and to manually configure the resulting certificate.

Certbot's nginx plugin doesn't understand that `*_by_lua_block` directives are expected to contain Lua code rather than nginx directives. It's probably unlikely that this will be addressed any time soon, but I opened [nginx: support \*\_by\_lua\_block directives · Issue #9066 · certbot/certbot · GitHub](https://github.com/certbot/certbot/issues/9066) in case anybody wants to give it a thumbs up or propose a PR.

---

<div class="post-metadata">

**Author:** ![slava1](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@slava1](https://community.letsencrypt.org/u/slava1)\
**Post date:** [October 14, 2021, 6:03am UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/7 "2021-10-14T06:03:44Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/letsencrypt/original/3X/c/a/ca6c06ea1ea201324bba7048c6841ce60236468d.png) [@system](https://community.letsencrypt.org/u/system)\
**Post date:** [November 13, 2021, 6:04am UTC](https://community.letsencrypt.org/t/bug-init-by-lua-block-and-certbot/162952/8 "2021-11-13T06:04:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
