Php Symfony docker配置
我正在尝试建立一个Docker映像来运行我的Symfony3应用程序 我有Php Symfony docker配置,php,nginx,symfony,Php,Nginx,Symfony,我正在尝试建立一个Docker映像来运行我的Symfony3应用程序 我有docker composer.yml和site.conf 在docker composer中,我定义了两个容器web和php,并链接这些容器: web: image: nginx:latest ports: - "80:80" volumes: - ./code/test:/var/www/test - ./site.conf:/etc/nginx/conf.d/de
docker composer.yml
和site.conf
在docker composer中,我定义了两个容器web
和php
,并链接这些容器:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./code/test:/var/www/test
- ./site.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./code/test:/var/www/test
我找到了关于如何设置我的site.conf的Official nginx:
server {
server_name test-docker.local;
root /code/test/web;
location / {
try_files $uri /app.php$is_args$args;
}
# DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
location / {
try_files $uri /app.php$is_args$args;
}
my site.conf:
server {
server_name test-docker.local;
root /code/test/web;
location / {
try_files $uri /app.php$is_args$args;
}
# DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
location / {
try_files $uri /app.php$is_args$args;
}
在我的docker.compose.yml和site.conf所在的目录中,我有一个代码目录,在代码目录的内部有test目录,在php应用程序的内部有test目录
我遇到的问题是,当我转到我的根urltest docker.local/
我得到的文件未找到
我输入了php容器以查看代码是否被复制到了正确的路径,它是/var/www/test/
当我输入我的web容器时,代码id位于同一路径/var/www/test下,但nginx容器的正确路径是否是nginx从…加载代码的路径。。。?即使如此,如果理论上代码应该从php容器加载,为什么nginx容器必须有代码的副本
volumes:
- ./code/test:/var/www/test
所以在nginx容器中可以省略这个卷server {
server_name test-docker.local;
root /code/test/web;
location / {
try_files $uri /app.php$is_args$args;
}
# DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
location / {
try_files $uri /app.php$is_args$args;
}
与
您的Nginx配置将根指向
root/code/test/web代码>但在我看来,该路径仅在docker主机上可用,而在docker容器中不可用。您的docker-compose.yml文件装载在容器中的/code/test
处,因此请尝试使用根/var/www/test/web代码>在nginx配置中