Error 404 Not Found on .php files only
See original GitHub issueI 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?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:18
Top Results From Across the Web
Custom 404 shows "File not found" for php files instead of ...
I believe paths and .htaccess work just fine but there has to be some trick with php. Here are few examples: When I...
Read more >SOLVED - Custom 404 shows “File not found” for php files ...
I am running PHP-FPM on WHM v72.05 with up to date software. I have a custom error page and I am having issues...
Read more >Error 404 Not Found on .php files only · Issue #1222 - GitHub
I have no problem serving .html files but when I try to navigate to a .php I receive Error 404 Not Found. This...
Read more >404 not found when trying to access index.php - Server Fault
there is a an index.php and btw every .php file that i`m trying to access i get 404. the error log is empty....
Read more >file_exists - Manual - PHP
In response to seejohnrun's version to check if a URL exists. Even if the file doesn't exist you're still going to get 404...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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