Report this

What is the reason for this report?

How to make nginx + php-fpm behave like apache on ".php/args" requests

Posted on September 25, 2019

Consider the following example URI

http://teste.com/test.php/8455

When accessing this on Apache the apache send the request to the “test.php” file. However when accessing the same URI on nginx with php-fpm he gave an not found error, why does it behaves different and how can i make they have the same behavior ?

This is my .htacces redirect configuration:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{ENV:REDIRECT_STATUS} 200 [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

And this is my nginx server configuration

server {
    listen   80;
    root /var/www/html;
    index index.php index.html;
    location ~ .php$ {
            try_files $request_uri $request_uri/ =404;
            fastcgi_pass 127.0.0.1:10000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location / {
        try_files $request_uri =404;
    }


    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/www;
    }
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @allangodoys,

I’ll suggest making the requests like


http://teste.com/test.php?8455=something 

or 

http://teste.com/test.php?8455

As I believe this is the proper way of handling such requests. If you want to keep the current convention, try to pass the $query_string variable in nginx:

try_files $uri $uri/ /index.php/$query_string;

Kind regards, Kalin

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.