【问题标题】:nginx configuration - route to root path dynamicallynginx 配置 - 动态路由到根路径
【发布时间】:2018-07-22 04:25:17
【问题描述】:

我不确定是否可以在这里做我想做的事情......但总之,当我去:

http://url/user,我希望 nginx 从 /dir/user/www/ 加载。 本质上,动态地将 http://url/$user/... 路由到 /dir/$user/www/

任何帮助将不胜感激。

【问题讨论】:

标签: linux ubuntu nginx url-rewriting


【解决方案1】:

使用alias 将请求重定向到特定文件夹。

定义指定位置的替换。比如下面的配置

location /i/ {
    alias /data/w3/images/;
}

根据“/i/top.gif”的请求,将发送文件/data/w3/images/top.gif。

示例:

location /valdeir {
    alias /var/www/html/user1;
}

location /psr {
    alias /var/www/html/user2;
}

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri /index.php?$args;
}

【讨论】:

    猜你喜欢
    • 2014-09-26
    • 2011-08-14
    • 2017-04-25
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多