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

Answer by Tero Kilkanen for nginx won't execute PHP code when redirected from a SEO like URL

$
0
0

The correct way to implement front-controller pattern in nginx is the following:

location / {
    try_files $uri $uri/ /index.php;
}

Your PHP location blocks look a bit odd. I guess that your objective with the configuration is to enable nginx to show a maintenance notice in /dd05cf208ebd3d4559f3af75016a1e3d.htm if the file exists.

This configuration looks correct to me, except that the try_files inside your @php block makes requests fail, since it makes nginx look for files with names specified in the URI, and with friendly URLs those files simply do not exist.

There is no reason to include that, so your PHP configuration should look like the following.

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

location @php {
    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;
}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>