Change nginx root directory dynamically

不羁岁月 提交于 2020-01-14 06:34:28

问题


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"


回答1:


something like this

server {
    ...

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

    ...

    location / {
      ...
    }
}


来源:https://stackoverflow.com/questions/57994296/change-nginx-root-directory-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!