【问题标题】:NGINX configuration: Angular SPA in root and Slim REST API in subfolderNGINX 配置:根目录中的 Angular SPA 和子文件夹中的 Slim REST API
【发布时间】:2015-08-23 10:05:43
【问题描述】:

我无法让它工作!

location ~ ^/(api) {
    #api requests
    include /etc/nginx/mime.types;
    index index.php;
    try_files $request_uri $request_uri/ /index.php?$query_string;
} 
location / {
    #angular app
    try_files $uri /index.html?$query_string;
}

我可以加载基本的api路径,即https://test.com/api,它会按预期返回404 json响应,因为访问api的根是非法的。

但是,尝试在 api 中运行任何路由,例如 https://test.com/api/v1/authenticate 并最终在第二个位置块中传递给前端应用程序!

【问题讨论】:

    标签: angularjs nginx slim


    【解决方案1】:

    好吧,经过一些实验,我确定将 api 放在子目录中会导致问题。我将 api 的 index.php/api/index.php 移动到根文件夹 (/) 并将其重命名为 api.php

    然后通过将我的 slim 应用程序组从 /v1 更改为 /api/v1,以下 nginx 配置现在可以正常工作:

    location ~ ^/api {
        try_files $request_uri $request_uri/ /api.php?$query_string;
    }
    
    location / {
        include /etc/nginx/mime.types;
        try_files $uri /index.html?$query_string;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-12
      • 2019-11-17
      • 1970-01-01
      • 2021-05-26
      • 2021-11-24
      • 1970-01-01
      • 2015-07-16
      • 2020-11-04
      相关资源
      最近更新 更多