Nginx + laravel + Vue SPA 返回除索引之外的所有文件的 index.php

Nginx + laravel + Vue SPA 返回除索引之外的所有文件的 index.php

我一直在尝试在我的服务器上运行一个简单的 Vue SPA,但是由于某种原因,索引页是唯一由 laravel 处理的页面,并且样式和 javascript 文件被 index.php 替换。

网络路线很简单,它们仅呈现视图:

Route::get('/', function () {
    return view('main');
});

而且NGINX的配置也是标准的:

server {
    listen 80 default_server;
    listen [::]:80;
    charset utf-8;

    root /home/gkovalechyn/gkovalechyn.net/public;
    index index.php index.html;

    server_name gkovalechyn.net www.gkovalechyn.net;

    location / {
        try_files $uri $uri/ /index.php /index.html;
        autoindex off;
    }

    location ~ /.well-known/ {
      root /home/gkovalechyn/gkovalechyn.net/.well-known;
      allow all;
    }

    access_log /var/log/nginx/gkovalechyn.net/access.log;
    error_log /var/log/nginx/gkovalechyn.net/error.log;

    error_page 404 /index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/gkovalechyn.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/gkovalechyn.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


#     Redirect non-https traffic to https
     if ($scheme != "https") {
         return 301 https://$host$request_uri;
     } # managed by Certbot

}

视图本身只是标题和脚本:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1">

        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>gkovalechyn.net</title>

        <!-- Fonts -->
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
        <link href="{{asset('css/app.css')}}" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div id="app">
            <router-view></router-view>
        </div>
    </body>

    <script src="{{asset('js/app.js')}}"></script>
</html>

现在,发生的情况是,这两个资产链接(js/app.js 和 css/app.css)确实获得了正确的链接(gkovalechyn.net/css/app.css 和 gkovalechyn.net/js/app.js)。

但是,如果我尝试访问这两个链接中的任何一个,它们始终是 public/index.php 文件。

编辑:
服务器上的文件:
在此处输入图片描述

相关内容