NGINX位置太长(巨大?)
NGINX 有一个类似于:NGINX位置太长(巨大?),nginx,location,massive,Nginx,Location,Massive,NGINX 有一个类似于: location ~ "^\/(place1|place2|...|place50)\/(service1|service2|...|service80)\-(else1|else2|...|else90)\/" {...} location ~ "^\/(word1|word2|...|word70)\/(place1|place2|...|place50)\-(else1|else2|...|else90)\/" {...} location ~ "^\/..
location ~ "^\/(place1|place2|...|place50)\/(service1|service2|...|service80)\-(else1|else2|...|else90)\/"
{...}
location ~ "^\/(word1|word2|...|word70)\/(place1|place2|...|place50)\-(else1|else2|...|else90)\/"
{...}
location ~ "^\/..."
问题是有很多地方、服务、文字和其他。所以位置是非常长的字符串。有可能把它们改短些吗?可能是大量的场所和大量的服务等等?还是什么?谁有经验
我想匹配的URI示例
/place23/service17-else87/
或
以及任何组合
对于每个位置,我们将使用一组规则。为了使用缓存并卸载我们的Apache
#proxy_cache start
set $do_not_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $do_not_cache 1;
}
if ($query_string != "") {
set $do_not_cache 1;
}
# Don't use the cache for logged in users or REBent commenters
if ($http_cookie ~* "wordpress_logged_in|bn_my_logged") {
set $do_not_cache 1;
}
if ($args ~* (show) ) {
set $do_not_cache 1;
}
ssi_types "*";
ssi on;
if ($do_not_cache = 0) {
set $memcached_key "SMREG|$request_uri";
memcached_pass memc_server;
ssi on;
}
您可以在位置块中使用正则表达式使它们匹配多个对象,而不是手动列出所有对象 e、 g 然而,正如穆罕默德·阿布沙迪暗示的那样,你所做的似乎相当愚蠢
您应该让您的应用程序进行路由,并决定是否可以缓存内容,然后使用实际设计用于缓存网页的内容,例如,不要试图将应用程序逻辑强制到Nginx中。您能给出您想要匹配的URI的示例吗?刚才添加了示例。您为什么在web服务器级别而不是应用程序级别处理这些问题?
#proxy_cache start
set $do_not_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $do_not_cache 1;
}
if ($query_string != "") {
set $do_not_cache 1;
}
# Don't use the cache for logged in users or REBent commenters
if ($http_cookie ~* "wordpress_logged_in|bn_my_logged") {
set $do_not_cache 1;
}
if ($args ~* (show) ) {
set $do_not_cache 1;
}
ssi_types "*";
ssi on;
if ($do_not_cache = 0) {
set $memcached_key "SMREG|$request_uri";
memcached_pass memc_server;
ssi on;
}
location ~* ^/world(\d{1,2})/place(\d{1,2})-else(\d{1,2})/ {
set $originalURI $uri;
fastcgi_param QUERY_STRING q=$originalURI&world=$1&place=$2&else=$3;
# or however you're passing it to your web server.
}