nginx-proxy: Error 404 Not Found on .php files only
I have an nginx reverse proxy container and also an nginx and a php-fpm one. I have no problem serving .html files but when I try to navigate to a .php I receive Error 404 Not Found.
This is the docker-compose.yml of nginx reverse proxy:
version: "2"
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
ports:
- "8080:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./vhost.d:/etc/nginx/vhost.d
networks:
default:
external:
name: nginx-proxy-net
This is the docker-compose.yml of my website:
version: "2"
services:
nginx:
image: nginx:latest
expose:
- 80
restart: always
volumes:
- ./html:/usr/share/nginx/html
environment:
- VIRTUAL_HOST=vhost.example.it
container_name: vhost-html
php:
image: php:7-fpm
expose:
- 9000
restart: always
volumes:
- ./html:/usr/share/nginx/html
environment:
- VIRTUAL_PROTO=fastcgi
- VIRTUAL_ROOT=/usr/share/nginx/html
- VIRTUAL_PORT=9000
- VIRTUAL_HOST=vhost-php.local
container_name: vhost-php
networks:
default:
external:
name: nginx-proxy-net
Also I created a per-VIRTUAL_HOST configuration file inside vhost.d folder:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass vhost-php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
Is this a bug with FastCGI?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 18
I had this probem too, and I really don’t know what change finally fixed it. However, here is my minimal
docker-compose.yaml
file that runs a simple PHP server (no MySQL, no special extensions) for a demo app:https://github.com/consilience/xero-php-oauth2-app/blob/docker-compose/docker-compose.yaml
There may be some clues there. One thing that may have fixed it was overriding the entire
/etc/nginx/conf.d/
directory rather than just add my ownconf
file. The nginx image comes with some default conf files that may be overriding settings in your conf file. The second thing was setting theworking_dir
for the nginx container.I’m exactly going through the same problems