[Bug]: Could not parse file error (at char 0), (line:1, col:1) because there's a "{" in a commented line of an NGINX server block config file
- Dominant language
- Python
- Stars
- 33.2k
- Forks
- 3.5k
- Avg merge
- 6d 10h
- Merged PRs (30d)
- 3
Description
### OS
Ubuntu 22.04.5 LTS
### Installation method
snap
### Certbot Version
4.0.0
### What happened?
I ran this command:
`sudo certbot renew --dry-run --dns-cloudflare-propagation-seconds 30`
It produced this output repeatedly for every server block configured in NGINX :
`Could not parse file: /etc/nginx/sites-enabled/adamlein.com due to Expected string_end, found 'server' (at char 0), (line:1, col:1)`
The same error also occurs when running:
`sudo certbot --installer nginx --dns-cloudflare --dns-cloudflare-credentials /etc/cloudflare/credential.ini --dns-cloudflare-propagation-seconds 30`
Along with help in [the community forum](https://community.letsencrypt.org/t/certbot-could-not-parse-nginx-server-block-because-char-0-at-line-1-is-the-s-in-server/235303), I found that the issue was not with the actual character 0 or line 1 column 1 (the word "server"). It was with a comment on line 68 in one of my server block config files.
Changing this:
```
location = /resume
# { rewrite .* /resume.php redirect; }
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
```
to this:
```
location = /resume
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
```
... removes the error and certbot is able to function properly.
Upon further investigation, simply adding a comment with the { character will cause the parsing error on the first character of the NGINX config file even if the parsing error is on a different line.
For example, adding "# {" between two lines of a rewrite will cause the problem:
```
location = /resume
# {
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
```
### Expected behavior
1. The error message should indicate the actual line number, character, and column where the parsing error occurs.
2. Certbot should ignore commented-out lines.
### Relevant log output
```shell
```
Contributor guide
Assessment
This issue has not been assessed yet.