【问题标题】:nginx error: openat() failed (20: not a directory) for imagesnginx 错误:图像的 openat() 失败(20:不是目录)
【发布时间】:2019-05-06 04:06:41
【问题描述】:

我有一个 PHP 项目,一个 REST API。 Nginx 配置适用于 API,但不适用于上传的图片

图像总是返回 404 错误

项目从/public目录开始,上传目录在public里面,所以图片访问url是这样的:

DOMAIN.COM/upload/201812/20181204133821.jpg

实际的NGINX配置是

server {
    listen 80;
    listen [::]:80;

    set $root_path '/usr/share/nginx/html/api/public';
    root $root_path;

    index index.php index.html index.htm;
    server_name api-eduplus.blanco-estudio.com;

    #try_files $uri $uri/ @rewrite;
    try_files $uri $uri/ /index.php?q=$uri&$args;

    location ~* \.(jpg|jpeg|png|gif)$ {
        root $root_path;
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    #error_log logs/error.log warn;
}

所以API从/public目录开始,图片上传到/public/upload/

还有。服务器上的 nginx 错误日志说:

2018/12/04 16:35:54 [error] 17338: *1 openat() "/usr/share/nginx/html/api/public/upload/201812/20181204133821.jpg" failed (20: Not a directory), request: "GET /upload/201812/20181204133821.jpg HTTP/1.1"

请帮忙,我真的卡住了

【问题讨论】:

  • 到底是什么问题?请求的文件是否存在?您在上传或下载文件时遇到问题吗?
  • @NicoHaase 文件存在。下载文件时服务器返回404错误
  • 并且该文件以适当的权限存在于该位置?
  • @NicoHaase 就在那个位置。我已经将文件的权限更改为 test 。 644、744、755、775、777。

标签: php api nginx server


【解决方案1】:

我刚刚在我的服务器上解决了这个问题。错误的原因是符号链接。

我刚刚在我的服务器的 nginx 配置中遇到了这个(不是很清楚)错误消息:

"/path/to/index.html" is not found (20: Not a directory)

经过反复试验,我确定实际原因是 nginx 无法访问站点的文档根目录,因为 root 的部分路径包含符号链接,但我设置了 disable_symlinks on;我的主要nginx.conf 文件。

注释掉 disable_symlinks on; 行或将其更改为 disable_symlinks off; 可解决此问题。

另见:

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 2013-03-28
    • 1970-01-01
    • 2017-12-05
    • 2012-09-02
    • 1970-01-01
    • 2016-11-18
    • 2010-12-16
    • 1970-01-01
    相关资源
    最近更新 更多