Paginate by Last Modified Not Working on NGINX

I’m iterating over recently modified pages and listing them using Hugo’s pagination.

I can view the list in the right order on my primary computer, and also when I run hugo server --bind= --baseURL= on a Ubuntu web server and view it on my computer (both devices are on the same network).

I run the below workflow on Ubuntu server to update the website:

cd /var/www/
git pull
hugo --cleanDestinationDir --minify
sudo systemctl reload nginx

where /var/www/ is the site root configured in NGINX.

This doesn’t list the pages in the correct last modified by order.

The list.html looks like:

{{ define "main" }}
    <h2>{{ .Title }}</h2>
    {{ .Content }}
    {{ range (.Paginate ( .Data.Pages.ByLastmod.Reverse )).Pages }}
        {{ partial "post_summary.html" . }}
    {{ end }}
    {{ partial "pagination.html" . }}
{{ end }}

and config.toml has:

enableGitInfo = true
paginate = 10

How can I ensure that last modified dates are consistent when I deploy the files?

Do I need to range in a different way to ensure consistency or is this an NGINX issue?

Nginx, or any other web server, has no part in this problem.

They will serve whatever static HTML,CSS and JS Hugo has generated.

The issue is that you somehow build the site differently on the prod server than during development.


During development I do:

rm -rf public/ resources/
hugo --cleanDestinationDir --minify
git push

And then on the server:

git pull
rm -rf public/ resources/
hugo --cleanDestinationDir --minify
hugo server --bind= --baseURL=

verify it from other devices on the network and then stop the Hugo server. Finally, a I do reload NGINX

sudo systemctl reload nginx

I dont think there’s any difference between how I build it on development and production server.

Can you share your project/repo? I am curious if you are invoking .Paginate/.Paginator more than once.

I would take the public folder from dev and from prod and run diff on them. Then you would know instead of guess.

1 Like

I can see the list in the correct order on dev and prod using Hugo. Its only when I deploy to NGINX, that this order changes.

For example “http:localhost:1313/blog/engineering” is ordered differently on Hugo and on the live website Saurabh Mishra - Engineering

What is your process for building for ‘dev’ and ‘prod’ versus ‘deploying to Nginx’?

As frjo mentioned the web server is not the issue (unless perhaps you are doing something silly like using the Hugo local server behind Nginx as a reverse proxy).

No! Not how to deploy a Hugo site. Deploy the contents of public to a dir on the server and serve that. It’s that simple.

1 Like

This is my workflow:

I think this is more likely the case.

I’m not doing this to deploy a Hugo site. I’m running this on a Ubuntu server to test the website from different devices on the same network (laptop, mobile).

I’m already deploying the contents of public/ directory and serving it with NGINX.

If you haven’t committed before using hugo server the Lastmod (which comes from GitInfo) will not yet be updated.

1 Like

Thanks @cshoredaniel !!

1 Like

I had .Paginator.Pages.ByLastmod in another place, which I changed to .Pages.ByLastmod. I see consistency in dev and prod environments.

Thanks @jmooring !

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