Nginx
來自不同文件夾的 Nginx 靜態文件記憶體
問題是 nginx 不顯示圖像,並且在某些文件夾上顯示 404 未找到。當我從配置中刪除記憶體時,一切正常。嘗試使用此配置配置 nginx 以記憶體靜態文件
location ~* \.(?:css|cur|js|jpg|jpeg|webp|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)$ { expires 1y; access_log off; add_header Cache-Control "public"; tcp_nodelay off; open_file_cache max=3000 inactive=120s; open_file_cache_valid 45s; open_file_cache_min_uses 2; open_file_cache_errors off; } # pass PHP scripts to FastCGI server location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; include fastcgi_params; fastcgi_intercept_errors on; } location / { try_files $uri $uri/ /index.php$is_args$args; }
這是錯誤日誌
2021/08/17 11:08:10 [error] 278986#278986: *3642 open() "/var/www/website/public/cache/medium/product/347/rC0dMIdOJIJNSmpKgm9pVqKVE59HKAl8SKujwxHF.jpg" failed (2: No such file or directory), client: 95.85.108.178, server: ozan.com.tm, request: "GET /cache/medium/produ ct/347/rC0dMIdOJIJNSmpKgm9pVqKVE59HKAl8SKujwxHF.jpg HTTP/2.0", host: "www.website.tm", referrer: "https://www.website.tm/"
nginx 顯示來自源的圖像: https ://website.tm/storage/velocity/category_icon_path/77/5wiasmLf6hQGAsjsTV4jXsjnG0ELm5ak0rgpV7c2.png
nginx 不顯示來自: https ://website.tm/cache/medium/product/353/jtTzvdT8ZmB6Lu7wFKj969Uzj0qqu1qRUt2CxEbz.jpg
您的圖像位置塊缺少
try_files
指令,該指令告訴 nginx 應該為到達該位置的請求提供什麼服務。添加
try_files $uri $uri/ =404;
到
location
塊。