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

}
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.

| improve this answer | |
  • 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 0: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 2:32
  • I have posted this new question. serverfault.com/questions/937297/… – Master Oct 26 '18 at 3: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 3: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 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.