【问题标题】:nginx URL-rewrite dynamic for all subfolders所有子文件夹的 nginx URL-rewrite 动态
【发布时间】:2013-12-19 12:48:55
【问题描述】:

从 apache 迁移到 nginx 时遇到以下问题: 在部署一个名为“apps”的文件夹时,包括大约 10 个带有 zend 框架 2 应用程序的子文件夹,我无法浏览我的 zf-routes (http 404)。

发生这种情况是因为我的 htaccess 没有被读取并且我的重写没有发生。

在我的 nginx 配置中定义所有项目时它会起作用,但这不是很动态,所有新项目都需要一个新条目,而 apache 读取所有文件夹中的 .htaccess 并自行完成。

有没有我没有找到的 nginx 指令来完成这个?

我目前正在尝试这个代码块:

location /apps/ {
        try_files $uri $uri/ /index.php;
    }

我知道这会导致 nginx 检查 /apps/index.php 而不是 /apps/(projectname)/index.php - 但我不知道如何更改。

【问题讨论】:

  • 为什么 location /apps 不是 location /
  • 它用于我们的 Intranet webserver,我们的 zend framework 2 应用程序位于 vhost 目录中的 /apps/ 下。
  • 好的,所以将/apps 添加到root 而不是location
  • 这不是解决方案,因为我无法在“应用程序”之外设置其他应用程序。我找到了一个可行的解决方案(在我自己的答案中)。

标签: apache .htaccess mod-rewrite nginx


【解决方案1】:
location /apps/(.*)/ {
        try_files $uri $uri/ /apps/(.*)/index.php?$args;
    }

这就是解决方案。我只是错过了 index.php 之前的部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多