I’m having a strange symfony problem. I’m trying to play with Symfony 3.4 and nginx.
I follow the “Create your First Page” tutorial but, only**/symfony/Symfony/web/app_dev.php** page is working when I using URL /symfony/Symfony/web/app_dev.php/lucky/number, IT SHOW
“nginx error! The page you are looking for is not found.”
LuckyController.php
<?php // src/AppBundle/Controller/LuckyController.php namespace AppBundleController; use SymfonyComponentRoutingAnnotationRoute; use SymfonyBundleFrameworkBundleControllerController; use SymfonyComponentHttpFoundationResponse; class LuckyController extends Controller { /** * @Route("/lucky/number", name="luckyNumber") */ public function numberAction() { $number = random_int(0, 100); return $this->render('lucky/number.html.twig', [ 'number' => $number, ]); } }
nginx.conf
server { listen 80; server_name domain.tld www.domain.tld; root /usr/share/nginx/html/; location / { try_files $uri /index.php$is_args$args; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ ^/index.php(/|$) { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_split_path_info ^(.+.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; internal; } location ~ .php$ { return 404; } error_log /var/log/nginx/project_error.log; access_log /var/log/nginx/project_access.log; }
routing.yml
app: resource: '@AppBundle/Controller/' type: annotation
Advertisement
Answer
I think the configuration you are using for nginx is the one for symfony 4.x and not 3.4
I see that you root
and location ~ ^/index.php(/|$) {
are wrong.
the root should contains “web” and the location should contains “app_dev” and and other on “app”.
check the documentation on symfony, it is well done 🙂
https://symfony.com/doc/3.4/setup/web_server_configuration.html#nginx
P.S. If you are starting symfony, I would suggest you to start with symfony 4, it is the newest version