【问题标题】:Requesting image returns 403/404请求图像返回 403/404
【发布时间】:2012-03-29 14:27:46
【问题描述】:

我正在使用 Nginx + Unicorn 和我的 rails 3.0.3 应用程序。

这是我的应用程序的 nginx 配置:

upstream unicorn {
  server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  root /home/deployer/apps/myapp/current/public;

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

这是应用程序public/images的目录列表:

lrwxrwxrwx  1 deployer admin     56 2012-03-28 17:06 other -> /home/deployer/other_images/
-rw-rw-r--  1 deployer admin   6646 2012-03-28 17:08 rails.png

如您所见,other 是一个符号链接。这是/home/deployer/other_images/的目录列表

-rw-r--r-- 1 deployer admin   2271 2012-02-03 17:24 1.jpg

在浏览器中,我可以拉出http://<domain>/images/rails.png,但http://<domain>/images/other/1.jpg 正在返回public/404.html 页面(“您要查找的页面不存在”)。

我做错了什么?文件/目录之一是否存在权限问题?我的 nginx 配置是否设置不正确?

更新

当我将以下内容添加到应用程序的 nginx 配置(root 下方)并请求 1.jpg 时,我得到了 403 Permission denied:

location ^~ /images/ {
  gzip_static on;
  expires max;
  add_header Cache-Control public;
}

【问题讨论】:

    标签: ruby-on-rails nginx unicorn


    【解决方案1】:

    我修好了。 /home/deployer/other_images 目录没有读取权限。

    【讨论】:

      【解决方案2】:

      我看到您已修复它,但对于遇到此问题的其他人,如果在您的 try_files 代码之后返回 404 总是好的做法...

      使用上面的例子

      try_files $uri/index.html $uri @unicorn =404;
      

      【讨论】:

        猜你喜欢
        • 2011-12-18
        • 2014-02-12
        • 1970-01-01
        • 2021-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-09
        • 1970-01-01
        相关资源
        最近更新 更多