"location ~ \.php$" or "upstrem php"? "location ~ \.php$" or "upstrem php"? nginx nginx

"location ~ \.php$" or "upstrem php"?


upstream usually is used when you have multiple application servers and nginx works as a proxy to load balance between those servers, you can give each a weight and you can take some servers offline for maintaining and stuff like that.

In this special case you use the upstream with only 1 application server which is actually also running on the local server.

The location method runs on matching locations that end with the extention .php and passing it to the php engine, I think both methods would work fine, but i guess the upstream method is better when you plan to scale your server or add more application servers, you can also add multiple upstreams, upstream php {} means that you defined an upstream with the name 'php'.

You pass things to the upstream almost like the same concept of named locations, but instead you proxy_pass to that block, in this case:

proxy_pass http://php;

Where php is the name of the upstream

Here's a link to the doc page of the upstream module, if you want to read more about it, I know it says "obsolete" but it's easier to read for a start, then you can find the link to the original doc page at the bottom, here's a link to it