Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony docker配置_Php_Nginx_Symfony - Fatal编程技术网

Php Symfony docker配置

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映像来运行我的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/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目录

我遇到的问题是,当我转到我的根url
test docker.local/

我得到的
文件未找到

我输入了php容器以查看代码是否被复制到了正确的路径,它是/var/www/test/

当我输入我的web容器时,代码id位于同一路径/var/www/test下,但nginx容器的正确路径是否是nginx从…加载代码的路径。。。?即使如此,如果理论上代码应该从php容器加载,为什么nginx容器必须有代码的副本

  • 您不需要在两个容器中重复:

    volumes:
         - ./code/test:/var/www/test
    
    所以在nginx容器中可以省略这个卷

  • 在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;
    }
    


  • 您的Nginx配置将根指向
    root/code/test/web但在我看来,该路径仅在docker主机上可用,而在docker容器中不可用。您的docker-compose.yml文件装载在容器中的
    /code/test
    处,因此请尝试使用
    根/var/www/test/web在nginx配置中