Score:0

CentOS - make Samba share available via nginx

us flag

I have a collection of files on a Windows share named \\winserver\bucket.

On a CentOS server, I am able to mount it so the content is available for perusal. I created an empty directory named /mnt/bucket for mounting.

sudo mount -t cifs -o credentials=/root/bucket.ini \\\\winserver\\bucket /mnt/bucket

The Windows credentials are stored in a relatively secure file (/root/bucket.ini), and I plan to put the mount directive in /etc/fstab at some point.

The CentOS server is running nginx, and I need to be able to serve the files in the share, download only, via http links.

As an example, someone clicking on a browser link named http://CentOSname/bucket/item/gizmo.pdf should receive \\winserver\bucket\item\gizmo.pdf as a downloaded file.

  • What's the best way to make this happen?
  • Does the nginx user account need to acquire proper permissions so it can access the files?
  • Are the parameters used to mount the Windows volume adequate for sharing it out to nginx?

--- Edit ---

Tero's answer does not work for me.

I added location and root parameters to the nginx.conf, and I get a 403 Forbidden error:

server {
    listen       80;
    listen       [::]:80;
    server_name  _;
    root         /usr/share/nginx/html;

    location /bucket/ {
       root /mnt/bucket;
    }

Adding autoindex on to see the directory contents produced the same error.

Score:0
us flag

nginx can serve any file that is available on any path. So, all you need to do is to mount the share like you have done, and then configure nginx to serve files from that directory using the root directive.

You also need to make sure that permissions on share are set so that nginx user can access the files. https://unix.stackexchange.com/questions/68079/mount-cifs-network-drive-write-permissions-and-chown has instructions how to set the share permissions.

us flag
Tero, this did not work. I'm receiving a 403 Forbidden error. I updated my question accordingly.
us flag
I added information about permissions to the answer.
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.