繁体   English   中英

如何使用 api 前缀在 NGINX 中配置 Laravel API 和 Angular 前端

[英]How to configure Laravel API & Angular front-end in NGINX using api prefix

我已经在我的 Nginx 服务器中使用 Angular 前端配置了我的 Laravel API,如下所示。 但是 Laravel API 不起作用。 你能告诉我我在这里做错了什么。

这是文件夹结构

www
-- my_domain
---- front-end index.html + css/js files + assets
---- api
------ index.php
------ public
-------- index.php

这是我正在使用的 nginx 配置

server {
    listen 80;
    server_name my_domain.com www.my_domain.com;
    root /var/www/my_domain.com;

    index index.html index.htm index.php;

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

    location /api {
        alias /var/www/my_domain.com/api/public;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }
}

这对我有用:

server {
    listen 80;
    server_name my_domain.com www.my_domain.com;
    root /var/www/my_domain.com/api/public;

    index index.html index.htm index.php;

    location /api/ {
        root /var/www/my_domain.com/api/public;
        try_files $uri  /index.php$is_args$args;
    }
    
    location / {
        root /var/www/my_domain.com;
        try_files $uri $uri/ /index.html;
    }

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

    location ~ /\.ht {
        deny all;
    }
}

从这里开始: 使用 nginx 在同一个域上提供 react 前端和 php 后端

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM