Nginx config for symfony on ubuntu

Master asked:

I want to setup symfony with nginx and this config is working fine

server {
    listen 80;
    root /src/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;

    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this

    error_log /var/log/nginx/symfony_error.log;
    access_log /var/log/nginx/symfony_access.log;

However i also want that on my server i should also be able to access files via app_dev.php and app_test.php as well

so far with above config. is working fine

but i also want and to work as well.

Currently its gives me 404 error

My answer:

Your configuration is, for some reason, set up to forward to PHP only requests to app.php.

    location ~ ^/app\.php(/|$) {

Since you want all PHP files, you should just allow all PHP files to be processed.

    location ~ \.php {

Of course, you also need to remove internal; as the comment instructs. This should be repalced with try_files $uri =404;. This is a security measure.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.