首页 > 解决方案 > Nginx 配置通配符第一个文件夹

问题描述

我正在努力让 nginx conf 以我们需要的方式工作。基本上在同一个域上,我们有许多应用程序,每个应用程序都在根文件夹中。当用户安装应用程序时,不可能知道文件夹的名称。

location / {
    try_files $uri $uri/ /index.php?$args /index.php?q=$uri&$args;
    }

location /myfiles {
    try_files $uri $uri/ /myfiles/index.php?$args /myfiles index.php?q=$uri&$args;
    }

如果我指定第二个文件夹,它会使 myfiles 中的应用程序正常工作,URL 可以正确解析。如果我不这样做,那么主应用程序会尝试解析 URL,但它会失败。

所以我想有类似的东西:

location /* {
    try_files $uri $uri/ /$folderrequested/index.php?$args /$folderrequested/index.php?q=$uri&$args;
    }

其中 * 可以是任何根文件夹,例如 myfiles、mycrm、myaccount,它们会将流量路由到该文件夹​​。

欢迎任何建议和想法!

标签: nginx

解决方案


将所有应用程序根目录放在父目录中。

server {
    listen .....;
    server_name ....;
    root /path/to/apps;
    index index.php index.html;

    location / {
    }

    location ~ \.php {
        fastcgi_pass localhost:8000;
    }
}

答对了。


推荐阅读