簡體   English   中英

404 未找到資產 nginx laravel

[英]404 not found for assets nginx laravel

我們在 nginx 上部署了一個 laravel 項目。 部分css和js文件無法訪問,返回404錯誤。 我們已經多次檢查路由和權限。 可能是什么問題呢?

更新:這是 nginx 配置:

server {
listen 80;
index index.php index.html;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    gzip_static off;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass xxx.xxx.xx.x:9000;
    fastcgi_cache_background_update on;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}


}

}

有些文件似乎 nginx 可以訪問它們的目錄,所以問題不會像我想的那樣來自 nginx 配置。 laravel 應該有問題,無法正確加載資產。 這是訪問返回 404 的文件的代碼:

<link href="{{asset('/css/bootstrap.css')}}" rel="stylesheet">

在黑暗中拍攝,您甚至沒有發布配置或錯誤日志,但請確保您不只是在處理“PHP”流量。

server {
    listen 80;
    server_name example.com;
    root /srv/example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

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

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

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

那是重要的部分。 它告訴NGINX:嘗試在配置的webroot(root)中找到URI(/img/sample.png)。 如果找不到,請將請求發送到 /index.php 文件。

http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM