Quantcast
Channel: nginx won't execute PHP code when redirected from a SEO like URL - Server Fault
Viewing all articles
Browse latest Browse all 4

nginx won't execute PHP code when redirected from a SEO like URL

$
0
0

Unlike other questions related to nginx not executing PHP files, mine does, the problem comes when I use SEO like urls instead and redirect to a php script, then instead of executing the code it sends the script as plain text to the browser.

Basically what I want is that every request send to the HTTP server for which there's no an actual file, index.php script will be executed and its output returned to the browser. But what is happening is that I'm getting the code inside index.php instead.

This is the section of my configuration file where the redirection is done. It's been actually translated from a former Apache's .htaccess file:

    location / {
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php break;
        }
    }

These are the PHP related directives, actually these are before the previous one in the configuration file:

    location ~ \.php$ {
        try_files /dd05cf208ebd3d4559f3af75016a1e3d.htm @php;
    }

    location @php {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/lib/php7.0-fpm/web4.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

I've been using Apache with mod_php for decades and the equivalent directives just worked out of the box, but I'm new with Nginx and I don't know where to start debugging this.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images