Enable/Disable PHP on Nginx for CDN Enable/Disable PHP on Nginx for CDN nginx nginx

Enable/Disable PHP on Nginx for CDN


PHP with nginx is very different than PHP with Apache, since there is no mod_php equiv for nginx (AFAIK).

PHP is handled by totally separate daemon (php-fpm, or by passing the request to an apache server, etc.) As a result, you can bypass php completely simply by letting nginx handle the request without passing it off to php-fpm or apache. There is a good chance that your nginx configuration already is setup only handoff .php files to php-fpm.

Now, if you're trying to have requests such as /some-style.css?foo=bar get handled by php, then I'd suggest simply segregating static resources from dynamic ones.

You could create a third domain, or simply use two separate directories.

/static/foo.css

vs

/dynamic/bar.css?xyz=pdq

You could then handoff to php inside the location blocks.

location ~ /static {   try_files $uri =404;}location ~ /dynamic {   try_files $uri =404;   include /etc/nginx/fastcgi_params;   fastcgi_pass 127.0.0.1:9000;   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}

With the above configuration, requests starting with /static will bypass php regardless of file extension (even .php) and requests starting with /dynamic will be passed on the php-fpm regardless of file extension (even .css)