动态更改Nginx根目录 [英] Change nginx root directory dynamically

查看:110
本文介绍了动态更改Nginx根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据特定条件将nginx根目录动态更改为另一个目录而无需重定向?例如,如果:

How to change nginx root directory to another directory dynamically without a redirect, depending on a certain condition? For instance, if:

$http_user_agent ~* "googlebot"

推荐答案

类似这样的

server {
    ...

    if ($allow = no) {
        set $variable "folder_1";
    }
    if ($allow = yes) {
        set $variable "folder_2";
    }
    root  /var/www/$variable;

    ...

    location / {
      ...
    }
}

这篇关于动态更改Nginx根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆