A
A
Alexey Vinogradov2017-10-21 16:10:52
Nginx
Alexey Vinogradov, 2017-10-21 16:10:52

Why doesn't map work in nginx?

Here is such a design:

map '$request_method $query_string $http_cookie $request_uri' $cache_uri {
    'POST ~* ~* ~*' null-cache;
    '~* ~*(.+) ~* ~*' null-cache;
    '~* ~* ~*(comment_author|wordpress_[a-f0-9]+) ~*' null-cache;
    '~* ~* ~* ~*(/wp-admin/|/xmlrpc.php)' null-cache;
    default $request_uri;
}

Map does not work in any way if there are several variables in the condition. Default is always selected. What is wrong with this design?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynn "Coffee Man", 2017-10-22
@Lynn

If you want a regular expression, then there must be one tilde at the beginning of the line

M
Mikhail Grigoriev, 2017-10-22
@Sleuthhound

I think Aleksey Vinogradov wants to make a beautiful nginx config for WP Super Cache to work without a mountain of ifs, as in many articles like this one, which is commendable, because If is Evil
But apparently, in nginx map, the regular expression does not work for several values, so neither ~* nor ~(.*) nor ~^(.*)$ will work.
But I would call an nginx expert here to authoritatively either confirm my guess or refute it.

A
Alexey Vinogradov, 2017-10-23
@alexjc

yes, I want for WP Super Cache. Tried one tilde at the beginning of the line. But then it looks like all 4 conditions are processed as a regular expression only to the first variable. In this case, the first condition in my construction does not work (the GET method and not POST), and the second condition always works. It seems that in map, regular expressions do not work with several variables, which is very unfortunate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question