Reputation: 11
guys,
I'm in the process of migrating an application using a front Apache reverse-proxy to a NGinx reverse proxy.
I'm trying to find the right way to convert this rule :
RewriteCond %{REQUEST_FILENAME} ^/web
RewriteCond %{REQUEST_FILENAME} !^/(.*)-staging/(.*)
RewriteRule /web/?(.*)$ https://mydomainename/$1 [L,NE,QSA,R=307]
From my understanding, it means "If the requested file name starts with /web, but doesn't contain the string '-staging/', then redirect to the same URI without the /web, using a 307 HTTP redirection.
I've been trying using locations to get this, then regex, (trying to prevent using evil "if"), but no way, it's beyond my knowledge.
Could someone help me to figure how to get this properly (the website will have heavy traffic, so, looking for something optimized), please ? Thank you in advance.
Upvotes: 0
Views: 183
Reputation: 15478
You can use the negative regex assertion for this case (good article about this subject is here):
location ~ ^/web/?(?!.*-staging/)(.*)$ {
return 307 https://mydomainname/$1$is_args$args;
}
For a better performance I recommend to enable and use the PCRE JIT. Please note that your system PCRE library must be compiled with this feature enabled (or you can build nginx from sources with custom PCRE library by yourself).
Upvotes: 1