php - Symfony docker configuration -
i trying build docker image run symfony3 app.
i have docker-composer.yml
, site.conf
in docker-composer define 2 containers web
, php
, link these cntainers:
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
i found offical nginx docs on how set site.conf:
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 other php files not matching front controller # prevents access other php files don't want accessible. error_log /var/log/nginx/project_error.log; access_log /var/log/nginx/project_access.log; }
in same dir have docker.compose.yml , site.conf have code dir , inside of code dir have test dir , inside test die php application.
the problem have when go root url test-docker.local/
i file not found
i entered php container see if code got copied correct path , /var/www/test/
when enter web container code id under same path /var/www/test correct path nginx container nginx loads code from...? , if why nginx container has have copy of code if in theory code should loaded php container?
you don't need repeat in both containers:
volumes: - ./code/test:/var/www/test
so in nginx container omit volume
replace in site.conf:
location / { try_files $uri /app.php$is_args$args; }
with
location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app_dev.php/$1 last; # dev mode # rewrite ^(.*)$ /app.php/$1 last; # prod mode }
Comments
Post a Comment