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

孤人 提交于 2020-01-06 06:47:52

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/54774343/how-do-i-deploy-laravel-5-7-and-angular-7-on-a-nginx-on-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!