I have a server with Nginx installed.I also have 2 domains pointing to that server. (domain1.com and domain2.com). The first domain (domain1.com) is the front website. The other domain (domain2.com) is the CDN for static content like: JS, CSS, images and font files.I setup domains config files and everything is running fine. The nginx server has PHP running on it.My question is: How to disable PHP on the second domain (domain2.com) unless the request has "?param=something" in the GET request?!It will be something like:// PHP is disabledif($_GET['param']){ // Enable PHP}or should I use:location ~ /something { deny all}And keep PHP running?!Note: I need php to process the param i pass to output some JS or CSS. 解决方案 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.cssvs/dynamic/bar.css?xyz=pdqYou 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) 这篇关于在Nginx上为CDN启用/禁用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!