Nginx正则表达式别名

时间:2017-08-13 18:47:28

标签: nginx

您好我想在nginx上的127.0.0.1:8080/article/1/foo或127.0.0.1:8080/article/1上提供/myproject/build/article/1/index.html。 '富'网址中的(slug)应该是可选的。

server {
    listen 127.0.0.1:8080;
    location ~ ^/article/(?<id>\d+)/(?<slug>.*)?{
        alias /myproject/build/article/$id/index.html;
    }
}

这不起作用。

1 个答案:

答案 0 :(得分:0)

您可以使用root指令



    server {
    listen 127.0.0.1:8080;
    location ~ ^/article/(\d+)/foo/(.*){
        alias /myproject/build/article/\1/index.html;
    }
}

OR

server {
listen 127.0.0.1:8080;
location ~ ^/article/(\d+)/foo/(.*){
    alias /myproject/build/article/\1/index.html;
}

}

解释here