【问题标题】:Assets Directory returning 404 via SSL on unicorn nginx Ubuntu 14资产目录在独角兽 nginx Ubuntu 14 上通过 SSL 返回 404
【发布时间】:2016-05-19 01:03:47
【问题描述】:

这是与this one 类似的问题,但建议的答案不起作用。

确认资产存在,重启nginx和unicorn服务。

$ service nginx restart
$ service unicorn_app_name restart

这是我的/etc/nginx/sites-enabled/[app_name] 配置。

upstream unicorn {
    server unix:/home/unicorn_user/apps/app_name/shared/sock/unicorn.unicorn_user.sock fail_timeout=0;
}

server {
 listen 80;
 server_name  staging.mydomain.org mydomain.org;

# Do not use a /tmp folder or other users can obtain certificates.
        location '/.well-known/acme-challenge' {
        default_type "text/plain";
        root        /etc/letsencrypt/webrootauth;
     }

        location / {
        rewrite ^/(.*) https://staging.mydomain.org/$1 permanent;
        }
}

ssl_certificate      /etc/letsencrypt/live/staging.mydomain.org/fullchain.pem;
ssl_certificate_key  /etc/letsencrypt/live/staging.mydomain.org/privkey.pem;

server {
    listen 443 ssl;

    server_name www.staging.mydomain.org;
    rewrite ^(.*) https://staging.mydomain.org/$1 permanent;
}

server {
    listen 443 ssl;
    server_name staging.mydomain.org;
    root /home/unicorn_user/apps/app_name/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 $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
        proxy_pass http://unicorn;
    }

    location ~ ^/(assets)/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
        #add_header Last-Modified "";
        #add_header ETag "";
    }
    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 60;
}

在错误和访问日志中看到 404。例如:

2016/05/18 07:46:01 [error] 2490#0: *4 open() "/home/unicorn_user/apps/app_name/current/public/assets/loading.gif" failed (2: No such file or directory), client: ip_address, server: staging.mydomain.org, request: "GET /assets/loading.gif HTTP/1.1", host: "staging.mydomain.org", referrer: "https://staging.mydomain.org/path/to/page"

所有资产的权限为644755,由unicorn_user 拥有并在同一组名中。

任何人都可以提出另一个建议来检查日志或配置,重新启动服务吗?是否存在 nginx 配置错误?

【问题讨论】:

    标签: ruby-on-rails-3 nginx


    【解决方案1】:

    我得到的 404 是因为在服务器查看 current/public/assets/ 时在 current/app/assets/ 中生成了一个特定资产 loading.gif

    我曾认为此设置会导致其他 javascript 错误,但这仅仅是因为我对 Rails 的无知太广了,我不知道在哪里寻找什么。

    【讨论】:

      猜你喜欢
      • 2012-03-15
      • 1970-01-01
      • 2014-02-20
      • 2013-01-10
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      相关资源
      最近更新 更多