Drupal 8 + nginx + php 7 图像样式:无法创建文件或文件夹

Drupal 8 + nginx + php 7 图像样式:无法创建文件或文件夹

我在 Centos7 上运行 Drupal 8.5.3,使用 Nginx + PHP7 + PHP 7 FPM 成功运行 Drupal 安装后,我想添加一篇文章,但图片缩略图返回 404 错误。图片上传到 sites/default/files 文件夹,但无法创建图片样式文件夹。 我的 drupal 状态文章上传图片后出现 404 错误图片样式

这是我的 nginx 配置

server {
        listen 80;

        # access_log off;
        access_log /home/drupal8.mds.com.vn/logs/access.log;
        # error_log off;
        error_log /home/drupal8.mds.com.vn/logs/error.log;

        root /home/drupal8.mds.com.vn/public_html;
        index index.php index.html index.htm;
        server_name drupal8.mds.com.vn;

        # Custom configuration
        include /home/drupal8.mds.com.vn/public_html/*.conf;

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

        location ~ '\.php$|^/update.php' {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                #fastcgi_split_path_info ^(.+?\.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 home/drupal8.mds.com.vn/public_html$fastcgi_script_name;
    }
        location ~ /\.(?!well-known).* {
                deny all;
                access_log off;
                log_not_found off;
        }

        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|is$
                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;
        }

     location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }
    location ~* ^/.well-known/ {
        allow all;
    }

    location ~ (^|/)\. {
        return 403;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }
     location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }

}

对于 drupal 7,我有同样的问题,但我可以在模块/图像函数 image_style_url($style_name, $path) 中破解核心{

  //Create derivated image if not exist ductm add
  if(!file_exists($file_url) && !file_exists($uri)){
    if(file_exists($path)){
      $currentStyle = image_style_load($style_name);
      image_style_create_derivative($currentStyle, $path, $uri);
    }
  }

  return $file_url;

权限 nginx 用户 sites/default/files/styles

答案1

据我所知为了解决这个问题,你应该检查以下参数:

走过 | :

检查文件夹及其子文件夹权限,确保上传文件夹具有足够的权限 0755。

检查以下目录以了解更多当您在日志中到达 404 未找到页面时发生的情况:

/var/log/nginx/*

/var/logs/nginx/* 

相关内容