首页 > 解决方案 > 在同一台服务器上部署 Angular 和 laravel(LEMP 堆栈)

问题描述

所以我有两个目录。一个用于角度,一个用于 laravel。我正在尝试将它们部署在同一台服务器(LEMP 堆栈)上。

这是我的 nginx 配置文件:

server {
    listen 80 default_server;

    charset utf-8;

    location / {
        root /var/www/client/;
        index index.html;

        try_files $uri $uri/ /index.html;
    }

    location /api {
        alias /var/www/server/public/;
        index index.php;

        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

角度工作正常。该网站已显示,但当我向我提出请求时,/api我只是得到“未找到”。例如/api/register不起作用。我究竟做错了什么?

标签: angularlaravelnginx

解决方案


可能是重复问题

在“fastcgi_param”之后添加此语句

fastcgi_param  REQUEST_URI        $request_uri;

Laravel 使用 $_SERVER['REQUEST_URI'] 变量进行路由,并从 fastcgi 传递给 Laravel。

参考:Laravel + AngularJS Nginx 路由


推荐阅读