How to use location before rewrite

I have a set of rewrite rules as

rewrite ^/(.*) /script.php?file=$1 last;

location ~ .php$ {
php proxy

but I want to make a few exceptions as

location = file1|file2|file3 {
static delivery

but rewrite will change any static file to php file before the latter

I cannot use rewrite inside the location, as it should generate php
before location (and I have other locations for subdirectories too).

Posted at Nginx Forum:

On Mon, Nov 04, 2013 at 08:51:53PM -0500, etrader wrote:

Hi there,

the answer to the question in the Subject: line is “you don’t”.

location = file1|file2|file3 {
static delivery

Depending on the full plan, perhaps either put your rewrites inside
“location / {}”; or add earlier rewrites of the form

rewrite ^(/file1)$ $1 last;


Francis D. [email protected]