laravel で画像を表示したいのですが、シンボリックリンクがうまく機能しません
--開発環境--
mac OS Monterey ver12.1
M1 チップ
laravel 8.77
docker
|---nginx
|---mysql
|---php
|---phpMyAdmin
nginx のdefault.conf
server {
index index.php index.html;
root /var/www/laravel/プロジェクト名/public;
location / { root /var/www/laravel/プロジェクト名/public; try_files $uri $uri/ /index.php?$query_string; } location ^~ /storage/ { root /var/www/laravel/プロジェクト名/public/storage/; //この行が怪しい気がする } location ~* ^/images/(.*\.(jpe?g|png|))$ { # ^ : 先頭マッチ # $ : 末尾マッチ # .* : 任意の文字が0回以上出現 # \ : 直後の文字をエスケープ # ? : 直前の文字が0回以上出現 expires 24h; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location ~ \.css { add_header Content-Type text/css; } location ~ \.js { add_header Content-Type application/x-javascript; }
}
画像の保存場所
/プロジェクト名/storage/app/public/images/○○.png
/config/filesystem.php
'links' => [ public_path('storage') => storage_path('app/public'), ],
phpコンテナ内で php artisan storage:link にてシンボリックリンク作成確認済み
ls -la 結果
lrwxr-xr-x 1 root root 39 Feb 27 03:00 storage -> /var/www/laravel/プロジェクト名/storage/app/public'
説明
viewの表示部
<img src=" {{ asset('/storage/images/id1_no1.png) }}" alt=""> <img src=" {{ asset('/storage/public/images/id1_no1.png) }}" alt=""> <img src=" {{ asset('/images/id1_no1.png) }}" alt=""> 表示の方法が間違っているのかと思い上記3種類試しましたが 表示されません
nginxについはまだ勉強中で、おそらくnginxのdefault.confファイルに問題があるのではないかとやんわり思っているのですが、お手数ですがどなたかお助けいただけると幸いです(泣)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。