Hugo behind nginx: permissions


#1

This problem must come up all the time but I haven’t found a solution by searching.

When hugo generates html pages running as an ordinary user e.g. peter, files are written like this
-rw-r–r-- 1 peter peter 11748 Feb 11 07:22 index.html

To be readable by nginx they need to be readable by www-data. (user peter is a member of www-data group but that doesn’t help). If I chown or chmod the html file tree so nginx can read it then next time hugo runs it fails because user peter doesn’t have permissions.

Any ideas (short of a horrible script to shuttle permissions back a forth!)?


#2

Hugo’s hugo server isn’t meant for production services like that but rather for dev, so I’m not sure if there’s a way to resolve that problem.


#3

I am not using the built-in hugo server, rather I am generating a tree of html (and css etc) files. nginx will handle the production load just fine and hugo is not running then - I only run it when I know a source file has changed.

The essential (and I would have thought common) problem is that I need to control permissions and/or ownership of the files hugo produces so nginx can read them.


#4

I see. I have a script to deploy which sets perms before rsync to Apache, come to think of it.


#5

So it’s a script then, bah! Kind of expected config items to set group and permissions of output files.


#6

I cannot say what the assumption was, when writing the files from Hugo. If trying to control it, I wonder how that would work, with multiple different target OS’s and file systems.


#7

I have a similar set up,my approach was to create a user just for hugo and set up a cron job within that user’s space.


#8

Um, they are. That’s what the third “r” means. The only reason that your web server wouldn’t be able to read them is if it couldn’t read the directory they’re in, or one of its parents.

-j


#9

Its fixed now. I am afraid I misdescribed the problem originally. It turns out the permissions issue was only in a new directory I had created under static. I must have created it with permissions of 700. I think hugo then propagated this same permission setting to the equivalent web directory. I chmod’ed that new directory and it is all fine.