【问题标题】:Nginx. Laravel. How to set up multiple endpoints in subfoldersNginx。拉拉维尔。如何在子文件夹中设置多个端点
【发布时间】:2018-04-11 06:45:32
【问题描述】:

我有这样的项目结构

<root>/public/laravel_app/index.php — Laravel index file

<root>/public/index.php — CraftCMS index file

我想在

加载 CraftCMS 应用程序

https://<domain>

Laravel 应用程序https://<domain>/laravel_app

这是我的vhost.conf

server {
    listen 443 ssl;

    index index.php index.html;

    root /var/www/public;

    ssl_certificate       /var/www/docker/certs/nginx.crt;
    ssl_certificate_key   /var/www/docker/certs/nginx.key;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

我已经查看了几乎所有相关的 SO 问题并尝试了很多东西,所以,如果可能的话,请发送与我的配置相关的建议。

我不是系统管理员,我是 Apache 用户(它以这种方式工作,无需任何调整),所以如果我遗漏了一些明显的东西,我深表歉意。

【问题讨论】:

  • CraftCMS 的 url 重写工作正常吗?所以只有 Laravel url 重写被破坏了。或者两者都不是作品?
  • @DharmaSaputra 它没有加载 Laravel。我无法获得那个端点。 nginx 正在通过<root>/public/index.php 传递所有内容。
  • @DharmaSaputra 或者我可以通过将 root /var/www/public; 更改为 root /var/www/public/laravel_app; 来使 Laravel 工作,但我不能同时工作

标签: php laravel nginx nginx-location


【解决方案1】:

我认为你应该重写 2 次 url,因为 laravel_app 有自己的 index.php 用于重写。

server {
    ...

    root /var/www/public;

    ...

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

    location /laravel_app {
        try_files $uri $uri/ /laravel_app/index.php?$args;
    }

    ...
}

希望这可行

【讨论】:

  • 哈利路亚!!非常感谢)
  • 如果我能以某种方式帮助你,请随时询问)
【解决方案2】:

改变

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

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

添加$uri/ 告诉 nginx 查找具有 uri 名称的目录。

【讨论】:

  • 谢谢,但它不起作用。它向我显示了一个 CraftCMS 错误页面,所以它正在加载 <root>/public/index.php
猜你喜欢
  • 1970-01-01
  • 2020-06-05
  • 1970-01-01
  • 2023-03-07
  • 2021-11-26
  • 2018-03-10
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
相关资源
最近更新 更多