Skip to content
Advertisement

nginx return file not found with nginx-proxy and doesn’t load static files

I’m using nginx-proxy-automation to run my php application which is written using CodeIgniter 4 and the app structure is the following:

JavaScript

the index.php file is available inside the public folder. The docker-compose.yml of php-application contains the following stuff:

JavaScript

Inside the php-application/docker-compose.yml I have this:

JavaScript

essentially I have three services:

  • php-fpm: which mount the application files in the /var/www/html folder, and in the environment section, I have specified the VIRTUAL_PORT as 9000 ’cause php-fpm runs over fastcgi. Then I linked the proxy network which is the network of your image.
  • database: runs within the app network
  • phpmyadmin: runs within the app network

The Dockerfile content of php-fpm contains the following stuff:

JavaScript

when I start the container using docker-compose up --build -d I get this message when I visit mysite.com (I have hidden the real domain for privacy):

File not found.

Inspecting the nginx log using sudo docker logs -f nginx I get:

JavaScript

For fix this problem, I have update the nginx.tmpl with this one.

The problem now is that when I load my site all the static files such js / image / css return 404.

What can I do for fix this?

Advertisement

Answer

In order to serve the static files from a container using the nginx proxy, the nginx proxy must have access to files statically… it would not ‘proxy’ but ‘read’ and serve the files… which means you must mount the app files into the proxy…

I would recommend you put up a new, light and clean nginx behind the nginx proxy along with your php-fpm service so you can have full management of your routes/locations,

First of all I have created a docker-compose.yml in my app that contains the following:

JavaScript

then, inside my app directory I have created the nginx configurations structure:

JavaScript

where I have conf.d:

JavaScript

then I have sites:

JavaScript

and nginx.conf:

JavaScript

the site load now but there are some issues:

  1. Performance issue: we have two nginx layer here and the load time is increased a lot
  2. If I browse some url like example.com/admin I get 404 from nginx, guess it’s a configuration issue on my own
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement