I am struggling with staticfiles and, since I'm new to docker and not quite fluent with Apache, I am not sure whether the problem comes from the former or the latter.
[the set up] I have a dockerized app with a WSGI server and I am using a non dockerized Apache as a proxy pass. The proxy works but since the WSGI server cannot serve static files, Apache has to do it. Here is the conf:
<VirtualHost *:80>
ServerName my.domain.name
ProxyPass /staticfiles !
<Location />
ProxyPass http://localhost:8000/
ProxyPassReverse http://localhost:8000/
</Location>
Alias /staticfiles "/var/lib/docker/volumes/app_static_volume/_data/"
<Directory "/var/lib/docker/volumes/app_static_volume/_data">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Despite all the directive I tried in the Directory
, I am still getting 403 errors. the log mentions an Permission issue.
[Mon May 06 17:06:27.531541 2019] [core:error] [pid 73031:tid 139870919952128] (13)Permission denied: [client 127.0.0.1:55892] AH00035: access to /staticfiles/jengu/jquery.datetimepicker.full.min.js denied (filesystem path '/var/lib/docker/volumes/app_static_volume') because search permissions are missing on a component of the path, referer: http://my.domain.name/
This makes sense:
ls -la /var/lib/docker/volumes/app_static_volume/_data
total 16
drwxr-xr-x 4 root root 4096 mai 6 14:33 .
drwxr-xr-x 3 root root 4096 mai 6 14:33 ..
drwxr-xr-x 6 root root 4096 mai 6 14:33 admin
drwxr-xr-x 3 root root 4096 mai 6 14:33 app
ls -la /var/lib/docker
total 84
drwx--x--x 15 root root 4096 mai 6 10:19 .
drwxr-xr-x 60 root root 4096 janv. 9 19:43 ..
drwx------ 2 root root 4096 août 13 2018 builder
.........
drwx------ 6 root root 4096 mai 6 14:33 volumes
#docker-compose
version: '3.7'
services:
web:
build:
context: ./app
dockerfile: Dockerfile.prod
command: gunicorn my_app.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/usr/src/app/staticfiles
ports:
- 127.0.0.1:8000:8000
env_file: .env
depends_on:
- db
db:
image: postgres:11.2-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file: .env.db
volumes:
postgres_data:
static_volume:
[What I tried] Sure I could change the path on which the volume is monted (and I tried it, just have to say : - ./web-app/application:/usr/src/jengu/staticfiles
), I could point it to somewhere in /home/myuser
but, anyhow, at one point, one component of the path will not be searchable.
[Mon May 06 17:53:18.038814 2019] [core:error] [pid 78453:tid 140402917062400] (13)Permission denied: [client 127.0.0.1:34708] AH00035: access to /staticfiles/app/jquery.datetimepicker.full.min.js denied (filesystem path '/home/david/Documents') because search permissions are missing on a component of the path, referer: http://my.domain.name/
Is there an elegant workaround so I wouldn't have to change massively the rights on my system? Did I understand docker volumes properly? Is my problem merely docker related or did I miss something in my apache conf file? Any help appreciated
[edit] I tried to use a symbolic link to overcome the issue.
ln -s /var/lib/docker/volumes/app_static_volume/_data/ /var/www/html/app/staticfiles
Does not seem to solve much
[Tue May 07 00:55:05.192193 2019] [core:error] [pid 5345:tid 140310969526016] [client 127.0.0.1:40766] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html/app/staticfiles, referer: http://my.domain.name/