【问题标题】:Nginx, static files for regex locationNginx,正则表达式位置的静态文件
【发布时间】:2016-04-20 15:27:52
【问题描述】:

我正在尝试配置以下规则: 当用户来到admin.mysite.com/username 他应该得到静态文件。我决定在 location 中使用正则表达式并得到这样的结果:

location ~ ^\/\w+$ {
    alias $site_root/html
}

但令我非常惊讶的是,nginx 不允许在没有捕获组和使用该组的情况下在正则表达式位置使用别名:

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

如果在正则表达式定义的位置内使用别名,则此类正则表达式应包含捕获,别名应引用这些捕获。

所以,我想找到一个workarounk,一些可以提供必要行为的技术。

【问题讨论】:

    标签: regex static-files


    【解决方案1】:

    为此使用重写,例如:

    server {
      root /some_root;
      rewrite ^/\w+$ html last;
    
      location /html {
        ...
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-11
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多