0

This is similar question to this one, but suggested answer does not work.

I have confirmed that the assets exist, and restart nginx as well as unicorn service.

$ service nginx restart
$ service unicorn_app_name restart

This is my /etc/nginx/sites-enabled/[app_name] config.

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

Seeing the 404's in the error and access logs. For example:

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"

Permissions on all the assets are 644 and 755, owned by unicorn_user and in same group name.

Can anyone make another suggestion for a log or configuration to check, a service to restart? Is there an nginx config misconfiguration?

1 Answer 1

0

the 404 i was getting was because one particular asset, loading.gif was generated in current/app/assets/ while the server is looking in current/public/assets/.

I had assumed that other javascript errors were being caused because of this setting, but it's simply because my Rails ignorance is so vast, I wasn't sure where to look for what.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.