Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs nginx-在不同端点和同一域上提供后端和前端服务_Angularjs_Laravel_Nginx_Frontend_Backend - Fatal编程技术网

Angularjs nginx-在不同端点和同一域上提供后端和前端服务

Angularjs nginx-在不同端点和同一域上提供后端和前端服务,angularjs,laravel,nginx,frontend,backend,Angularjs,Laravel,Nginx,Frontend,Backend,我已经用php7.1、mysql等在OSX上安装了nginx。。。基本测试示例正在运行 当我试图将nginx配置为在user.domain.dev/api/…上为Laravel后端服务时。。。和user.domain.dev/…上的角度前端。。。我得到404或403。Nginx错误日志主要是 /Users/name/Projects/domain.dev/api.domain.dev/" is forbidden 或 我似乎不理解nginx的location指令,所以它们指向了一个错误的目录。

我已经用php7.1、mysql等在OSX上安装了nginx。。。基本测试示例正在运行

当我试图将nginx配置为在user.domain.dev/api/…上为Laravel后端服务时。。。和user.domain.dev/…上的角度前端。。。我得到404或403。Nginx错误日志主要是

/Users/name/Projects/domain.dev/api.domain.dev/" is forbidden

我似乎不理解nginx的location指令,所以它们指向了一个错误的目录。谢谢你的建议和指导

我的配置是:

nginx.conf

servers/domain.dev.conf


主要问题是root指令的使用不一致。您有两个文档根,每个应用程序一个,但仅在两个位置指定。在服务器{…}块级别没有指定根,因此如果-d$request|u filename无意义,location~*\.jpg|jpeg|gif|css|png|js|ico|html$将始终导致404响应,等等

阅读以了解nginx如何处理请求

但是您可能应该在服务器块中设置前端根目录,并在location/api块中使用后端根目录覆盖它

这将把后端文档根放在:/Users/name/Projects/domain.dev/api.domain.dev/api-注意,URI总是附加到根

还要注意,^~修饰符用于使前缀位置优先于同一级别的正则表达式位置。有关详细信息,请参阅

我不喜欢你设计的裸体if积木。如果-d$request_文件名可能应替换为,如果$host~*^www\..,则可能应使用单独的服务器块替换。更多信息,请参阅

location/api块中的try_files语句包含不正确的默认URI,它可能是/api/index.php?$query_字符串。

员工用户是否有权访问根指令中指定的目录?如果不是,这将解释403错误。对于找不到的index.php文件,您没有在index指令中指定它。您只有index.html。
/Users/name/Projects/domain.dev/frontend.domain.dev/build/index.php" failed (2: No such file or directory)
user name staff;  
worker_processes auto;

events {  
    worker_connections  1024;
}

http {  
    include mime.types;
    default_type application/octet-stream;

    ssl_certificate ssl/nginx.crt;
    ssl_certificate_key ssl/nginx.key;

    access_log /usr/local/var/log/nginx/access.log;
    error_log /usr/local/var/log/nginx/error.log;

    sendfile on;
    keepalive_timeout 5;

    gzip  on;

    include servers/*.conf;
}
server {
    listen 80;
    listen 443 ssl http2 default_server;

    server_name domain.dev *.domain.dev www.domain.dev;

    charset utf-8;

    # removes trailing slashes (prevents SEO duplicate content issues)

    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www

    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    ##
    ## Backend HTTP server
    ##

    location /api {

        root /Users/name/Projects/domain.dev/api.domain.dev;
        index index.php;

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

        location ~ \.php$ {
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    try_files $fastcgi_script_name =404;
                    fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi.conf;
            }
    }

    ##
    ## Frontend HTTP server
    ##

    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }

    location = /favicon.ico { 
        access_log off; 
        log_not_found off;
    }

    location = /robots.txt  { 
        access_log off;
        log_not_found off; 
    }

    location / {
        root /Users/name/Projects/domain.dev/frontend.domain.dev/build;
        index index.html;
    }

    location ~ /\. {
        deny all;
    }
}
server {
    root /Users/name/Projects/domain.dev/frontend.domain.dev/build;

    location / { ... }
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { ... }

    location ^~ /api {
        root /Users/name/Projects/domain.dev/api.domain.dev;
        ...
    }
}