[英]Nginx is downloading the index.php instead of executing - Docker + symfony + php-fpm
When I visit "localhost:8000" I get a 403 Forbidden.当我访问“localhost:8000”时,我收到 403 Forbidden。 But, if I go to "localhost:8000/index.php", the file is being downloaded.
但是,如果我 go 到“localhost:8000/index.php”,文件正在下载。
I know there is a lot of questions like this around there, but I swear I have checked like 50 I none of those solutions seem to work for me, or maybe I am doing something wrong... I am completely new in Docker, be patient:)我知道周围有很多这样的问题,但我发誓我已经检查了 50 个,但这些解决方案似乎都不适合我,或者我做错了什么......我是 Docker 的新手,是病人:)
I suspect that the problem is related to the configuration of nginx, or perhaps the php-fpm service is not working or not being able to communicate with nginx service.我怀疑问题与nginx的配置有关,或者php-fpm服务没有工作或无法与nginx服务通信。
These are the related files:这些是相关文件:
php.conf (nginx configuration file): php.conf(nginx配置文件):
server {
listen 80;
root /public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
docker-compose.yml: docker-compose.yml:
version: "3.4"
services:
php:
build:
context: .
target: app_php
args:
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
STABILITY: ${STABILITY:-stable}
restart: unless-stopped
volumes:
- php_socket:/var/run/php
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
webserver:
image: nginx:latest
ports:
- 8000:80
volumes:
- ./nginx/conf.d/php.conf:/etc/nginx/conf.d/php.conf
- ./public:/usr/share/nginx/html
depends_on:
- php
mysql:
image: mysql:8.0
environment:
- MYSQL_USER=root
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=db
volumes:
- symfony-data:/var/lib/mysql
volumes:
php_socket:
symfony-data:
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###
###> doctrine/doctrine-bundle ###
db-data:
###< doctrine/doctrine-bundle ###
My proyect folders:我的项目文件夹:
Any help would be very appreciated.任何帮助将不胜感激。 Thanks to everyone!!
谢谢大家!!
I tried a lot of changes in the configuration files of nginx and fpm, as well as the docker-composer file, but nothing works...我尝试了nginx和fpm的配置文件,以及docker-composer文件中的大量更改,但没有任何效果......
add line index index.php index.html;添加行索引 index.php index.html; in nginx configuration file
在 nginx 配置文件中
server {
listen 80;
root /public;
index index.php index.html;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.