情況:
Laravel 提供了 php artisan storage:link?命令,用于創建符號鏈接(Symbolic Link),將 storage/app/public?映射到 public/storage。但是上傳圖片之后 文件目錄確實有 但是無法訪問。
1.?刪除已經創建的
?rm -rf public/storage
?2. 重新創建符號鏈接:
?php artisan storage:link
3. 檢查符號鏈接是否正確:
?ls -l public/storage
2. 檢查文件權限
1. 設置目錄權限:
chmod -R 755 storage/app/public
?2. 設置文件所有者(根據 Web 服務器用戶調整):
?sudo chown -R www-data:www-data storage/app/public
3. 檢查服務器配置
確保 Nginx 或?Apache?的配置正確,允許訪問?public/storage?目錄。
server {
? ? listen 8080;
? ? server_name 10.10.205.19;
?
? ? root /path/to/your/project/public;
? ? index index.php;
?
? ? location / {
? ? ? ? try_files $uri $uri/ /index.php?$query_string;
? ? }
?
? ? location /storage {
? ? ? ? alias /path/to/your/laravel-project/public/storage;
? ? ? ? try_files $uri $uri/ =404;
? ? }
?
? ? location ~ \.php$ {
? ? ? ? include snippets/fastcgi-php.conf;
? ? ? ? fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # 根據你的 PHP 版本調整
? ? }
}