I'm setting up a little web project for studies purpose consisting in two docker containers (a nginx
container and a php
container).
I've linked my containers and I'm now able to request both static files (.js, .css ...) directly from the nginx container and requests on /index.php
through a socket to the php
container.
But so far I'm not able to process requests on /
.
I'm relying on this example to build my nginx configuration. The code sample and explanation bellow caught my attention :
location / {
index index.html index.php;
}
[...]
location ~ \.php$ {
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
[A request “/”] is matched by the prefix location “/” only, therefore, it is handled by this location. Then the index directive tests for the existence of [index.php]. [If it] exists, then the directive does an internal redirect to “/index.php”, and nginx searches the locations again as if the request had been sent by a client.
Since I'm using docker containers the nginx process and php workers work in two different filesystems. So the index.php
file is in the php
container and not in the nginx
. Therefore nginx won't find this file and return a 404 error.
Does that mean that I should -even if it sounds dirty to me- copy the php sources twice, in both containers? Or is there a better way to solve this problem? Would returning a 301 to /index.php
be the right way?