NGINX在单个域上的多个Laravel项目

在工作中,我们有一个单独的临时域名服务器,例如https://staging.example.com 。 我们最近决定在一台新的服务器上从Apache切换到NGINX,并且我们遇到了Laravel路由问题。

我们所有的laravel应用程序都位于登台服务器上的子目录中,像这样。

  • https://staging.example.com/app1/public
  • https://staging.example.com/app2/public

我已经尝试configurationLaravel文档中指定的NGINX conf文件,但在访问任何二级路由时获取404,即https://staging.example.com/app1/public/a/b

使用类似下面的configuration,我可以访问应用程序中的所有路线。

location @laravel { rewrite /app1/public/(.*)$ /app1/public/index.php?$1; } location / { try_files $uri $uri/ @laravel; } 

但是,我们有很多应用程序托pipe在这个服务器上,我们不希望每次我们想要添加一个应用程序到服务器时都需要更新一个NGINX conf文件。

有没有办法构build一个适用于任何子目录的重写,并保持Laravel的路由系统工作?

注意:我也试过这个重写rewrite (.*)/(.*)$ $1/index.php?$2 ,并且不适用于二级路线。

你的第一个捕获可能太贪婪,你应该限制它使用:

 rewrite ^(/[^/]+/[^/]+)/(.*)$ $1/index.php?$2 last; 

在正则表达式中查看这个有用的资源