nginx doesn't read mounted /usr/share/nginx/html

1

Goal:

I am using an NGINX container in which I mount a remote SSHFS filesystem into /usr/share/nginx/html, the purpose is to use each time a new stateless nginx container but with the same persistent content.

Performed steps:

-Made sure SSHFS server is up and running.
-On the nginx container (sshfs client) I mounted the remote sshfs file system into /usr/share/nginx/html

/ # sshfs  root@X.X.106.181:/data /usr/share/nginx/html
root@X.X.106.181's password:  / #

-The mount looks fine:

/ # mount | grep sshfs

root@35.185.106.181:/data on /usr/share/nginx/html type fuse.sshfs
(rw,nosuid,nodev,relatime,user_id=0,group_id=0)  

/ # df -h
Filesystem                 Size  Used Avail Use% Mounted on  
rootfs                     886G  681G  161G  81% /  
none                       886G  681G  161G  81% /  
tmpfs                      7.9G     0  7.9G   0% /dev  
tmpfs                      7.9G     0  7.9G   0% /sys/fs/cgroup  
/dev/sda1                  886G  681G  161G  81% /gns3  
shm                         64M     0   64M   0% /dev/shm  
root@X.X.106.181:/data  976M  2.6M  907M   1% /usr/share/nginx/html  

-Put there a couple of files and they are readable by everyone:

/ # ls -la /usr/share/nginx/html

total 36 drwxr-xr-x 1 root root  4096 Aug 20 11:48 . drwxr-xr-x 5 root
root  4096 Aug 20 11:36 ..
-rw-r--r-- 1 root root   537 Aug 20 11:48 50x.html
-rw-r--r-- 1 root root   612 Aug 20 11:48 index.html  
drwx------ 1 root root 16384 Aug 20 11:23 lost+found
-rw-r--r-- 1 root root   310 Aug 20 11:48 test.php

Desired result:

Whatever the new nginx container, I mount the remote SSHFS and I have the same information browsed by the user.

Obtained result:

Nginx doesn't read the content of /usr/share/nginx/html. It acts as there is no index file.
Nothing shows up in browser:

enter image description here


nginx Logs:

/ # tail /var/log/nginx/error.log
2017/08/20 15:47:16 [crit] 139#0: *3 stat() "/usr/share/nginx/html/" failed (13: Permission denied), client: 192.168.122.247, server: ajnouri.local, request: "GET / HTTP/1.1", host: "192.168.122.100"  
2017/08/20 15:47:16 [crit] 139#0: *3 stat() "/usr/share/nginx/html/404.html" failed (13: Permission denied), client: 192.168.122.247, server: ajnouri.local, request: "GET / HTTP/1.1", host: "192.168.122.100"  
2017/08/20 15:47:16 [crit] 139#0: *3 stat() "/usr/share/nginx/html/404.html" failed (13: Permission denied), client: 192.168.122.247, server: ajnouri.local, request: "GET / HTTP/1.1", host: "192.168.122.100"  

Looks like "www-data" need to write to the directory.

####################### UPDATE

So, managed to make "www-data" user as it was a regular user on the server and the sshfs client succeeded to mount "/var/www" using "www-data"

At the server I changed the owner of "www-data" home directory (/var/www) to www-data:www-data

/ # chown -R www-data:www-data /var/www

/ # ls -la /var/www
total 36
drwxr-xr-x 1 www-data www-data  4096 Aug 20 11:48 .
drwxr-xr-x 5 root     root      4096 Aug 20 11:36 ..
-rw-r--r-- 1 www-data www-data   537 Aug 20 11:48 50x.html
-rw-r--r-- 1 www-data www-data   612 Aug 20 11:48 index.html
drwx------ 1 www-data www-data 16384 Aug 20 11:23 lost+found
-rw-r--r-- 1 www-data www-data   310 Aug 20 11:48 test.php

######################

Doesn't seem to solve the issue.


Nginx container (sshfs client) and sshfs server use the same OS:

/ # lsb_release -a

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

AJN

Posted 2017-08-20T12:41:46.270

Reputation: 399

2What errors you see in the nginx server logs? – Jakuje – 2017-08-20T15:11:14.580

Thanks @Jakuje. I forgot about logs. Added to the question. – AJN – 2017-08-20T16:05:11.093

Wouldn't be a good idea to mount the directory with the permissions of the nginx user, rather than to leave them world-readable? The error is obviously that it can not read them (for whatever reason). – Jakuje – 2017-08-20T16:09:22.697

@Jakuje I changed the owner of the directory to www-data:www-data, but it doesn't solve the issue. – AJN – 2017-08-20T16:20:29.030

Answers

3

For those that it may help in future, I had this issue, and after a little more searching I found that adding -o allow_other to the mount call managed to make it work

No idea what it's doing under the hood, or why it's necessary (setting uid or gid doesn't do anything), but there we go.

Source: https://stackoverflow.com/questions/29330382/how-to-enable-writing-to-sshfs-directory-in-php

LordAro

Posted 2017-08-20T12:41:46.270

Reputation: 131

0

  1. Try to mount sshfs by www-data like here
  2. Try to set root directory outside sshfs and connect to site
  3. Check that you have line in config

    index index.html index.htm;

or connect to site by full link, for example 192.168.0.20/index.html

  1. tail -f you nginx access and error logs

Quarind

Posted 2017-08-20T12:41:46.270

Reputation: 11

Hi @Quarind, I managed to mount to sshfs server using "www-data" user (as it was a regular user) and changed the ownership of its home directory on the server to "www-data". no changes, still permission denied – AJN – 2017-09-05T13:13:52.140