Code Monkey home page Code Monkey logo

Comments (8)

char101 avatar char101 commented on May 10, 2024

Also with path info, this line try_files $uri =404; on top of php_fastcgi.conf does not work because $uri may not point to a real path.

from nginxconfig.io.

char101 avatar char101 commented on May 10, 2024

Alternatively to check the existence of the file

if (!-f $document_root$fastcgi_script_name) {
    return 404;
}

from nginxconfig.io.

char101 avatar char101 commented on May 10, 2024

Also this line is required in php_fastcgi.conf

fastcgi_param				PATH_INFO       $fastcgi_path_info;

from nginxconfig.io.

0xb4lint avatar 0xb4lint commented on May 10, 2024

It works perfectly fine for me.
(Maybe you've skipped the index.php fallback?)

If you check the major PHP frameworks' nginx documentation:

You will see only the fastcgi_split_path_info ^(.+\.php)(/.*)$; is required, everything else is defined in the stock fastcgi_params file.

try_files $uri =404; is needed for handling a non existing php file with nginx 404 error page rather than PHP-FPM's No input file specified. message.

Also If Is Evil, nginxconfig.io does not use any if in configurations.

from nginxconfig.io.

0xb4lint avatar 0xb4lint commented on May 10, 2024

Now I understand your issue with try_files.
I was preparing the Magento support and there is the following URL structure for setup: /setup/index.php/navigation.
The try_files failed, so I've moved it from php_fastcgi.conf to location ~ \.php$ {}, so it can be overridden.

from nginxconfig.io.

char101 avatar char101 commented on May 10, 2024

Hmm I don't know, it seems to me that this regex \.php$ will not match e.g. /index.php/some/path/info, will it?

By the way, I encountered the problem when installing moodle.

As for the frameworks documentation, it does not uses path info, the route is passed as a query string as you can see in this line try_files $uri $uri/ /index.php?$query_string. Older PHP applications still uses index.php in the URL, which is why the part after \.php still need to be matched to support path info in the URL.

from nginxconfig.io.

char101 avatar char101 commented on May 10, 2024

Example from nginx website:

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }

    # Mitigate https://httpoxy.org/ vulnerabilities
    fastcgi_param HTTP_PROXY "";

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;

    # include the fastcgi_param setting
    include fastcgi_params;

    # SCRIPT_FILENAME parameter is used for PHP FPM determining
    #  the script name. If it is not set in fastcgi_params file,
    # i.e. /etc/nginx/fastcgi_params or in the parent contexts,
    # please comment off following line:
    # fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
}

from nginxconfig.io.

0xb4lint avatar 0xb4lint commented on May 10, 2024

Thanks for your inputs @char101!

I've made a lot of research in this topic and commited (c25228e) the Legacy PHP routing option.
It utilises the fastcgi_split_path_info directive and PATH_INFO param only if enabled.

Also made a PR to Laravel docs in this topic: laravel/docs#4847

from nginxconfig.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.