php-fpm + nginx - nginx web server cannot access file generated by php-fpm
MarkBFamFour opened this issue · 1 comments
Hi,
I have the following setup:
docker-compose.yml
version: '3.1'
services:
webserver:
image: 'nginx:alpine'
working_dir: /application
volumes:
- '/var/www/php/MyApp:/application'
- './phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'
- '/var/stuff/ExternalFiles:/var/stuff/ExternalFiles'
ports:
- '8205:8205'
environment:
APP_ENV: "production"
php-fpm:
build: phpdocker/php-fpm
working_dir: /application
volumes:
- '/var/www/php/MyApp:/application'
- './phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini'
- '/var/stuff/ExternalFiles:/var/stuff/ExternalFiles'
phpdocker/nginx/nginx.conf
server {
listen 8080 default;
client_max_body_size 40M;
access_log /var/log/nginx/access.log;
root /application/public_html/;
index index.php;
# try to serve file directly, fallback to index.php
location / {
try_files $uri /index.php$is_args$args;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass legacy-php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
One of my app's scripts generates a CSV file and deposits it in /application/public_html/attachments. This is all done by the php-fpm container, as it's a PHP process that pulls data from a database and collates it into a CSV. The prioblem is when I want to download the CSV file, the link is processed by the nginx server in the webserver container and it can't access it, it gives me a 404 and the log shows Permission Denied for access to /application/public_html/attachments/myfile.csv.
How do I get permissions parity between the two containers to allow one to access files from the other?
Sorry Mark but this is not a support forum for general docker questions, but for issues with the docker-compose generator and the site itself. You obviously need to store your files in a volume that's accessible to both containers and created with the correct permissions for nginx to be able to access it.