Score:1

404 when Serving Static Files Owned By Another User From /opt

gs flag

OS = Debian 11

I have edited default nginx (version 1.18.0, installed from Debian repository) config as below:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            try_files $uri $uri/ =404;
    }

    location /torrent/ {
            autoindex on;
            alias /opt/docker/qbittorrent/downloads;
    }
}

to serve my downloaded files with qbittorent docker container on HTTP protocol. However, I get a 404 Not Found error when I visit either /torrent/ or /torrent/some_folder/some_name.some_extension.

If important, these have rw-r--r-- permission and are owned by docker_qbit:docker though the web server is installed by a sudoer.

Forever Cuber avatar
cd flag
I think I may be able to answer this but I need to understand the requirements a little better. You mean for the files to have permission `rw-r--r--` or "644" with the Owner being "docker_qbit" and the Group being "docker"? I may be wrong, but if this is correct then I think the solution would be to add "nginx" user to the "docker" Group.
Mohammad Qodrati avatar
gs flag
@Cnasp Yes, all are correct.
sv flag
Did you check the permission of `/opt/docker/qbittorrent/downloads`, `/opt/docker/qbittorrent`, `/opt/docker`, `/opt` and `/`?
Mohammad Qodrati avatar
gs flag
@PothiKalimuthu Except the last one (i.e., root `/`) which I don't know what its permission is, they are all 755; however, the last but two are owned by `root:root`.
Score:0
gs flag

Thanks to all. The problem was omitted trailing / after the address in the alias directive.

Score:0
cd flag

What is happening is that the NGINX user doesn't have permission to traverse the directory you have specified in your alias.

Your requirements indicate we cannot change the permissions on the target directory.

The only solution I see would be to add the main nginx (www-data) user to the docker group. That way the webserver should be able to access the specified directory without changing its permission.

If the default nginx user on Debian 11 is www-data.

Assuming that to be the case, the command to do this would look like this:

usermod -a -G docker www-data

That command will modify the user "www-data" by adding them to group "docker".

To be sure what user is running nginx you could look at the output of this command:

ps -eo user,comm | grep nginx

Once complete you can reload nginx and see if the content is now available.

systemctl reload nginx
Mohammad Qodrati avatar
gs flag
Thanks. The outputs of the last command are `root nginx` and `www-data nginx`. But the first command run with a *sudo*er says that `usermod: user 'nginx' does not exist`
Forever Cuber avatar
cd flag
So your "nginx" user is actually "www-data". I will update my answer for this.
Forever Cuber avatar
cd flag
Changed nginx user to match your system user. I hope this gets you going. Let me know! =)
Mohammad Qodrati avatar
gs flag
Unfortunately, nothing changed with adding this user to the group.
Forever Cuber avatar
cd flag
Is there anything in `/var/log/nginx/error.log that may be useful?
Mohammad Qodrati avatar
gs flag
Yeah! Thanks. It shows that the final problem is the omitted trailing `/` after the address in the `alias` command. Solved, thanks.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.