【问题标题】:nginx 404 error with laravel image interventionnginx 404错误与laravel图像干预
【发布时间】:2017-08-03 10:22:39
【问题描述】:

目前,每次尝试通过 URL 操作访问图像时,laravel 图像干预包总是返回 404 错误。

我的图片存储在“storage/app/images”文件夹中

我的 nginx 配置:

    server {
    listen   80;

    server_name ######;
    rewrite ^(.*) http://#####$1 permanent;
    }server {
    listen   80;

    # access_log off;
    access_log /home/#####/logs/access.log;
    # error_log off;
    error_log /home/#####/logs/error.log;

    root /home/######/public_html/dtu-feedback-api/public;
    index index.php index.html index.htm;
    server_name ######;

    # Custom configuration
    include /home/######/public_html/dtu-feedback-api/*.conf;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }
    if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
    }

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_buffer_size 32k;
            fastcgi_buffers 8 16k;
            fastcgi_busy_buffers_size 32k;
            fastcgi_temp_file_write_size 32k;
            fastcgi_intercept_errors on;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~ /\. {
            deny all;
    }
    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }
    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }
    location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
            gzip_static off;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
    }

    location ~* \.(txt|js|css)$ {
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
    }
}

这是日志:

*1 open() "/home/#####/public_html/dtu-feedback-api/public/imagecache/medium/placeholder1.png" failed (2: No such file or directory)

看起来它试图在imagecache 路径而不是storage 路径中查找图像。

那么请您帮我解决这个错误,谢谢。

【问题讨论】:

  • Laravel 有来自 root-laravel-direction/public 的 BaseRewrite URL。所以我认为你需要将图像存储路径移动到公共文件夹。
  • 但是这些是用户上传到服务器的图像,我应该将它们保存到public吗?

标签: php laravel nginx intervention


【解决方案1】:

我找到了解决方案,删除后

location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
            gzip_static off;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
    }

然后图片链接开始工作

【讨论】:

  • 您是否找到任何解决方案来保持该配置块并使其正常工作?
猜你喜欢
  • 1970-01-01
  • 2018-05-20
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
相关资源
最近更新 更多