简体   繁体   中英

How do i deploy Laravel 5.7 and Angular 7 on a Nginx on a server

server {
    listen 80;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name example;

     location / {

    index index.html;
    try_files $uri $uri/ /index.html =404;

      }

      location /api {

    root /var/www/html/example/public;
    try_files /index.php =404;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_param APP_ENV dev;
    fastcgi_pass 127.0.0.1:9000;

     }

above is my server configuration but only angular is working but laravel is not reachable, it keeps showing not found

After reading the Nginx documentation about request processing and using the alias . I came up with the following:

server {
    listen 80;
    server_name example.com;

    # This is the "last resort" nginx will direct to when no other matches with location have been found.
    # It will only look for a file named index.html
    location / {
        root /location/of/angular;
        index index.html;

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

    # All requests that start with /api are directed to the laravel location.
    # It will only look for a file named index.php
    location /api {
        alias /location/of/laravel;
        index index.php;

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

    # All files that end with .php are through fastcgi
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_param APP_ENV dev;
        fastcgi_pass 127.0.0.1:9000;
    }
}

Sidenote: this has not been tested in a working environment but might help you in the right direction.

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