Nginx proxy or rewrite depending on user agent, no if
I need to serve different files depending on the user-agent. This is an unusually simple requirement, one step away from serving files in general.
standard answer , use the instruction if
.
However, it seems to be well known what if
not to use .
So the answer at this point seems to be Apache, but I said that my boss nginx was a useful product. Any suggestions?
source to share
If you read if it is evil , you will notice that it has the following quote:
The only 100% safe things which may be done inside if in location context are:
return ...;
rewrite ... last;
Anything else may possibly cause unpredictable behaviour, including potential
SIGSEGV.
So...
anger if
is only applicable for use in the location block
inside a location
-block there are two and only two guaranteed block usage preserves if
:
- one lone statement
return ...;
- one lone statement
rewrite ... last;
- (note that an empty
if
block can also lead to problems)
not guaranteed to keep the usage if
in the location block might work, but needs testing
source to share