Incredibly peculiar nginx error with Hugo

Hi guys.

Here is my repository: Hash Borgir / psychedelicsdaily.com-hugo · GitLab

For example, if I go to Extended State DMT: Prolong the DMT Flash - Using Psychedelics Daily for a happy & healthy life

I see this in nginx logs:

openat() "/var/www/psychedelicsdaily.com-hugo/public/blog/extended-state-dmt-prolong-the-dmt-flash/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/banners/dream/img/
banners/dream/img/banners/dream/img/banners/dre... (2: No such file or directory), client: 108.1

I’ve looked up and down my source. I’ve gone over my nginx config. I can’t figure out where this is coming from. When I open the inspection panel in browser on this page, there are no 404s no redirects, no missing files… I can’t find anything. However, this is plaguing my logs and I could use some help in figuring this one out.

Thanks guys! :slight_smile:

This looks like a server config problem, not a Hugo problem, perhaps related to URL rewrites… it looks like a URL is being re-written over and over and over…

I suggest you raise a question on Stack Overflow or similar.

Ok thanks.

dunno if this is relevant, or created by Chrome View Source, but there are a lot of html errors in the page.

  • <img class=“shadow caption right-img” src=https://www.psychedelicsdaily.com/img/placeholder.png data-src=b.caapi.jpg title=“Banisteriopsis Caapi” alt=“Banisteriopsis Caapi” style=width: width=300>

  • closing non open p-tags

  • violation of tag nesting rules

maybe the server get’s confused …

I hadn’t noticed that. Thanks. I’ll check it out.

<div class="caption-wrapper">
    <div style='float: {{.Get "align" }}'>
        {{ if eq $bundle_type "leaf" }}
			<img class="shadow caption {{ .Get "align" }}-img" src="{{ .Site.BaseURL}}img/placeholder.png" data-src="{{ .Get "src" }}" title="{{ .Get "title" }}" alt="{{ .Get "title" }}" style="width: {{ .Get "width" }};"  width="300" />
		{{ else }}
			<img class="caption {{ .Get "align" }}-img" src="{{ .Site.BaseURL}}img/placeholder.png" data-src="{{ .Get "src" | absURL }}" title="{{ .Get "title" }}" alt="{{ .Get "title" }}" style="width: {{ .Get "width" }};"  width="300" />
		{{ end }}
        <p class="caption-text">{{ .Get "title" }}</p>
    </div>
</div>

It’s an image tag, so I’m specifing a default width as well as a CSS style for it. Is that wrong?

I call it like this:

{{< imgcap src="p.harmala.jpg" title="Peganum Harmala" align="right" >}}

Sometimes I need to specify a width=“” in imgcap shortcode call, and sometimes when I don’t, I need CSS to handle the width.

So I don’t think this is wrong, but I could be wrong.

Update on the original issue: I unproxied cloudflare, and after a while redid the proxying over cloudflare and the looped image path error has gone away. I’ve no idea what that was about.

Now I have errors like this:

2024/05/17 19:57:10 [error] 50587#50587: *5148 openat() "/var/www/psychedelicsdaily.com-hugo/public/tags/img/banners/dream/280.jpg" failed (2: No such file or directory), client: 108.162.245.79, server: psychedelicsdaily.com, request: "GET /tags/img/banners/dream/280.jpg HTTP/2.0", host: "www.psychedelicsdaily.com"
2024/05/17 19:58:40 [error] 50587#50587: *5154 openat() "/var/www/psychedelicsdaily.com-hugo/public/authors/img/banners/dream/326.jpg" failed (2: No such file or directory), client: 108.162.246.6, server: psychedelicsdaily.com, request: "GET /authors/img/banners/dream/326.jpg HTTP/2.0", host: "www.psychedelicsdaily.com"

And the path should be /img/banners/dream/326.jpg and not authors/img/banners/dream/326.jpg, and nowhere in my source can I find a problem, or in my nginx config, so I’m still looking.

In case anyone has any ideas at all, here is my nginx conf.

server {
    listen 80;
    server_name psychedelicsdaily.com www.psychedelicsdaily.com;
    return 302 https://www.psychedelicsdaily.com$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name psychedelicsdaily.com www.psychedelicsdaily.com;
    root /var/www/psychedelicsdaily.com-hugo/public;
    index index.html index.php;

    access_log off;
    error_log /var/log/nginx/psychedelicsdaily.com-error.log;

    if ($host = 'psychedelicsdaily.com' ) {
        rewrite ^/(.*)$ https://www.psychedelicsdaily.com/$1 permanent;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /drugs/[A-Z] {
        # rewrite_by_lua 'ngx.exec(string.lower(ngx.var.uri))';
        rewrite ^(.*)$ $scheme://$host$uri_lowercase permanent;
    }
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/psychedelicsdaily.com-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/psychedelicsdaily.com-0001/privkey.pem; # managed by Certbot

    error_page 404 = /;

}

I even commented out to disable these unrelated few rewrites in my nginx config, but that still didn’t help.

Ok, thanks.

Also, I could use some tips on debugging this p tag mismatch and other errors. I have a css/html validator link at the bottom of every page, but I overlooked that the link is always to the home page and that has no errors. I’ll correct that to every page is uniquely tested at the validator.

I just checked single.html template and one by one all the partials being called in it, and the source, and I can’t find any out of order p tags. I could use some tips on how to find missing elements.

Feel free to grab my repository.

I used The W3C Markup Validation Service on your posted page which gives you list of problems

maybe related to your HTML minimizer / optimizer ?

Chrome source and the output from the validator tell your image tag is (end only)

... style=width: width=300>

your template code:

style="width: {{ .Get "width" }};"  width="300"

returns

style="width: ;"  width="300"

the style is falsy, but the browsers fix that up but I would recommend to check the rsult of .Get and if it results in an empty style omit the whole attribute, if an attribute like with is empty omit that

regarding the images: i generated your site and all references are absolute pointing to /img so I guess thats also something old /fauty left in your nginx deployment or caching…

to analyze the tag problem I would

copy past the unminified HTML page code to the validator and check it results.

Example:
for
image

check the source

<a href="/drugs/25h-nbome/">**<span class="h5">25H-NBOMe *******<span>******</a>```

the span should be a closing tag
search the generating code

grep -r 'span class="h5"' themes/hugo-universal-theme/layouts/
themes/hugo-universal-theme/layouts/partials/most_read.html:                    <a href="{{ .url | absURL }}"><span class="h5">{{ .title }}<span></a>
themes/hugo-universal-theme/layouts/partials/related.html:                    <a href="{{ .RelPermalink }}"><span class="h5">{{ .Title }}<span></a>

so two faulty places.

send you some DM on other problems - these would be off topic here

Thank you.