部署 Assets production 下 403 forbidden

autumnwolf · 2014年01月06日 · 最后由 autumnwolf 回复于 2014年01月06日 · 2670 次阅读

在 public 目录下放置文件 logo.png 或者建立文件夹 images/logo.png, 本地可以直接访问http://localhost:3002/logo.png ,但是服务器 production 下是 404 (The page you were looking for doesn't exist.). 然后,assets/application.js 可以直接在本地访问,但是服务器端 403 forbidden。 查了一些解决方案,貌似应该是文件权限问题,但是 asset 整个文件夹(production 下在public/assets)给了 755 权限,还是同样的错误。 求帮助!

ps: nginx 配置

upstream unicorn { server unix:/tmp/unicorn.haizheba.sock fail_timeout=0; }
server {
  listen 80;
  server_name haizheba.com;
  root /home/william/apps/haizheba/current/public/;
  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control 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;
}

检查一下 Nginx 的配置?

#1 楼 @_samqiu 编辑,贴上了 nginx 配置。

你 nginx 也用 william 这个用户跑,试试

#2 楼 @autumnwolf

public 下有 logo.png ,但是在线上访问是 404? public/assets 有 application.js ,但是访问是 403?

部署时都经过 assets precompile 了吗?你的 assets 目录下都有什么文件?

#4 楼 @_samqiu 是的 嗯 欲编译了,里面主要是 application.js / .css 和一些图片,截图 #3 楼,改用户之后好用了,同样感谢!

#3 楼 @search 谢谢,之前是用 nginx 这个用了,改成 william 之后好用了!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号