【问题标题】:Nginx configuration with Laravel API + vuejs使用 Laravel API + vuejs 配置 Nginx
【发布时间】:2018-09-25 00:12:12
【问题描述】:

我在 vuejs 上有前端的应用程序,它通过后端的 laravel api 工作。我使用 Laravel Passport 进行授权。 当我通过 localhost:8000 上的集成 laravel Web 服务器(工匠服务)启动应用程序时,它运行良好,没有任何错误。 但是当我将它移到本地网络服务器时,我遇到了一些问题。

当我尝试发帖请求时

axios.post('http://project.local/oauth/token', data)

我收到 http 错误 405(不允许的方法)。 我从 CSRF 令牌中排除了所有路由,添加了 CORS 标头,但无论如何它都不起作用。正如我在 localhost:8000 上所说的,它运行良好。

我没有找到有关此问题的任何信息,也无法自己解决。有人知道吗?提前致谢。

我的 nginx 配置

    server {
    listen  80;

    root /home/me/project/frontend/dist;
    index index.html index.php;
    server_name project.local;

    access_log off;
    error_log /home/me/project/backend/error.log notice;

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

    location /api/v1 {
         root /home/me/project/backend/public;
         rewrite ^/api/v1/(.*)$ /$1 break;
         try_files $uri $uri/ /index.php?$query_string;
    }

    location /oauth/token {
        root /home/me/project/backend/public;
        rewrite ^/oauth/token/(.*)$ /$1 break;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {

            set $newurl $request_uri;
            if ($newurl ~ ^/api/v1(.*)$) {
                set $newurl $1;
                root /home/me/project/backend/public;
            }

            if ($newurl ~ ^/oauth/token(.*)$) {
                set $newurl $1;
                root /home/me/project/backend/public;
            }

            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param REQUEST_URI $newurl;
            fastcgi_param SCRIPT_FILENAME 
        $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
    location ~ /\.ht {
            deny all;
    }
}

【问题讨论】:

  • @samayo 这不是重点。我刚刚更改了 stackoverflow 的名称,并且出现了语法错误

标签: laravel nginx vue.js


【解决方案1】:

也许它是一个缓存!我刚刚解决了这个问题,原来是缓存cloudflare

将所有文件缓存为 index.html

【讨论】:

    猜你喜欢
    • 2017-07-25
    • 1970-01-01
    • 2016-09-24
    • 2020-12-27
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2020-08-27
    相关资源
    最近更新 更多