如何在 NGINX 中继续位置匹配?

如何在 NGINX 中继续位置匹配?

我已经在(虚拟)服务器上进行了设置fastcgi_cache。但是,我想关闭文件夹wp-admin和文件的wp-login.php缓存。配置的问题是,当文件夹或文件匹配时,它不会将请求传递给 PHP,而是由 NGINX 提供 .php 文件。(我已经简化了配置文件,所以它不是太大。)

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=cache:30m;
fastcgi_cache_key "$scheme$host$uri$is_args$args";

server {
    ...

    fastcgi_cache cache;
    fastcgi_cache_valid 200 10m;

    location / {
        index index.html index.php;
    }

    location ~* ^/wordpress/(wp-login\.php|wp-admin) {
        fastcgi_cache off;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

问题是 PHP 从未从 获得请求/wordpress/wp-login.php。如何解决这个问题?

答案1

尝试一下这个:

location ~* ^/wordpress/(wp-login\.php|wp-admin) {
    fastcgi_cache off;

    location ~ \.php$ {
         fastcgi_pass   unix:/var/run/php5-fpm.sock;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
    }
}

location ~ \.php$ {
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

相关内容