I'am trying to convert my personal development setup from local php/ nginx setup to a docker setup. Almost everything is working great, the only issue I'am having right now is that all static content (*.css/*.js/*.jpg etc
) is responding in a 403 forbidden. I have been scrolling and trying solution of the inter net the whole day, but non seem to be working. Most found issues had answers that the container user should be set to another user (uid 1000 in my case). Doing this results in Permission denied 13 error on nginx container boot.
Hope somebody here has the solution so I can finalize my new local setup.
Host: Linux OS (popOS)
Containers used:
- NGINX - nginx:latest
- PHP - php:8.2-fpm
For both containers I created a dockerfile.
When accessing the localhost page, everything except local static files work fine. So localhost:3030 loads the index.php files etc. Only when trying to access for example localhost:3030/dist/images/test.png I get a forbidden error.
Now I take it that this means nginx has no access to the files. I only don't see how to give this access. Because this is a local dev environment I am not copying all files in the container only using a volume bind to the project folder in a docker-compose.yml,
and the same volume binding in the php container.
I hope I am missing something stupid, because it feels this should be working.
Project files example:
/public/
/public/index.php
/public/dist/
/public/dist/images/test.png
Docker files:
Below the setup of the docker files at this moment.
docker-compose.yml:
version: '3.7'
services:
ngnx:
build: ./nginx/
container_name: nginx-container
restart: unless-stopped
links:
- php
volumes:
- ./www/html/:/var/www/html/
- ./www/logs/:/var/log/nginx/
php:
build: ./php/
container_name: php-container
restart: unless-stopped
expose:
- 9000
volumes:
- ./www/html/:/var/www/html/
./nginx/Dockerfile
FROM nginx:latest
COPY ./default.conf /etc/nginx/conf.d/default.conf
./php/Dockerfile
FROM php:8.2-fpm
RUN apt-get update -y && apt-get upgrade -y
./nginx/default.conf
Very basic nginx file because I first want a fully working environment before starting to tweak this.
server {
listen 80 default_server;
root /var/www/html/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log /var/log/nginx/error.log;
error_log /var/log/nginx/error.log error;
sendfile off;
client_max_body_size 100m;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass php-container:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
}