php - Nginx。拉拉维尔。如何在子文件夹中设置多个端点

标签 php laravel nginx nginx-location

我有这样一个项目结构

<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 用户(它以这种方式工作,无需任何调整),所以如果我遗漏了一些明显的东西,我深表歉意。

最佳答案

我认为你应该重写 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;
    }

    ...
}

希望这能行得通

关于php - Nginx。拉拉维尔。如何在子文件夹中设置多个端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012691/

相关文章:

laravel - 为什么我应该在 Laravel 5 中使用 Facades

php - Laravel - 将数组转换为 eloquent 集合

reactjs - 当我转到我的域名时,它会转到我的应用程序,但只在地址栏中显示 IP 地址

node.js - Linux:在 nginx 上设置 node.js

php - Laravel/Eloquent 查询出错

基于响应的 Nginx 上游重试

PHPDoc 和 PhpStorm : indicate the return type of a magic method

php - Auth::check() 不持久 Laravel 5.2

php - Cloud9 云 IDE 和 CakePHP

php - 更改密码用户 laravel 5.3