0

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
        internal;
    }

    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. http://127.0.0.1/api/check is working fine

but i also want

http://127.0.0.1/app_dev.php/api/check and http://127.0.0.1/app_test.php/api/check to work as well.

Currently its gives me 404 error

UPDATE

server {
    listen 80;
    root /src/web;
    client_max_body_size 30m;
    client_body_buffer_size 128k;

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

    location ~ \.php {
        root /src/web/;
        fastcgi_pass unix:/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;
        try_files $uri =404;
    }

}
Master
  • 105
  • 1
  • 5

1 Answers1

0

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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • Thanks man , you are the only one who solved my issue thanks. SO was not able to solve it so i posted here. Thanks. One thing more i want . now i have to use app.php or app_dev.php for every request. i want that by default all request go to app.php so that i dont need to type that in url . but if some has app_dev.php or app_test.php then it should use that url instead of prepending app.php. Is this possible ? – Master Oct 26 '18 at 00:01
  • That should already be working, if you made only this change. Otherwise, you can post a new question. – Michael Hampton Oct 26 '18 at 02:32
  • I have posted this new question. https://serverfault.com/questions/937297/nginx-symfony-make-app-php-and-app-dev-php-work-together – Master Oct 26 '18 at 03:01
  • Eh? The config you posted in that question isn't what I advised you to do here. You made a whole extra `location` block when you were supposed to have changed the existing one that I pointed out. – Michael Hampton Oct 26 '18 at 03:04
  • I didn't get where to put `try_files $uri =404; `, do i need to replace `try_files $uri /app.php$is_args$args;` with `try_files $uri =404;` or i need to keep that as it is and replace `internal` with `try_files $uri =404;` at bottom of location block? – Master Oct 26 '18 at 03:41
  • I did write that you need to replace `internal;` with `try_files $uri =404;`. I didn't say anything about the other `try_files`. – Michael Hampton Oct 26 '18 at 03:43
  • OK sorry , i tested that but it does not work , i mean `http://127.0.0.1/api/check` works but `http://127.0.0.1/app_dev.php/api/check` does not work . it only work if i replace the other try_files with ur one but then `http://127.0.0.1/api/check` dont work – Master Oct 26 '18 at 03:50
  • @Master You need to do _both_ of the things shown in this answer. – Michael Hampton Oct 26 '18 at 03:51
  • I have added the final config in my question , please chk if its what you were saying? – Master Oct 26 '18 at 03:53