I already saw other posts here about a similar issue, but I think mine needs a different solution because the other posts didn't help.
I am running two separate containers with Docker: For php-fpm
and for nginx
.
When I try to display text using index.html
file it's all ok, but when I change the file name to index.php
it downloads a "download" file instead.
I'm not sure if it's only because of my default.conf
file or because of how I setup my containers.
This is my docker-compose.yml
:
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql
container_name: mysql
tty: true
ports:
- "4306:3306"
volumes:
- ./src:/var/lib/mysql
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
This is my default.conf
:
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}