首页 > 解决方案 > 如何在 nginx 中动态匹配 URL 位置

问题描述

我是 nginx 的新手,我试图阻止它返回 403 的特定 url。当 url 为:http://mysite.domain.com/user/test.test/files/person 时,我需要返回 403。 jpg?=下载. 但是这个 url --> location /user/([a-zA-Z.]+.?$)/files/ 不起作用。请帮忙。:(

server {
    listen       80;
    server_name  localhost;

    error_page 403 /403.html;
    location = /403.html {
        root    /usr/share/nginx/html/;
                internal;

    }

    location /test {
        return 502;
    }

    location /user/([a-zA-Z.]+\.?$)/files/ {
        return 403;
    }

    location /user/files/ {
        return 503;
    }

    location / {
        return 500;
    }

}

标签: nginxnginx-locationnginx-confignginx-ingress

解决方案


推荐阅读