简体   繁体   中英

Deploy angular and laravel on same server (LEMP stack)

So I have two directories. One for angular and one for laravel. I am trying to deploy them on the same server (LEMP stack).

This is my nginx conf:

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;
    }
}

Angular works fine. The website is shown but when I make requests to /api I just get "not found". For example /api/register doesnt work. What am I doing wrong?

Might be duplicate issue

Add this statement after "fastcgi_param"

fastcgi_param  REQUEST_URI        $request_uri;

Laravel uses $_SERVER['REQUEST_URI'] variable to route and it is passed to Laravel from fastcgi.

Ref : Laravel + AngularJS Nginx routing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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