Reputation: 360
I use Active Storage successfully when developing (Disk storage), but when application is deployed (Amazon S3 storage) all my attachments are not found.
Uploading works without any problems - files appear in S3 bucket and active storage database records are created. But any time I use .variant()
or url_for()
, all those files are missing.
Rails logs doesn't tell me anything, as if request did not happen at all. That makes me think that my web server configuration is wrong.
This is my current nginx configuration:
upstream my_app {
server unix:/srv/example.com/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
root /srv/example.com/current/public;
include h5bp/directive-only/ssl.conf;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include h5bp/basic.conf;
include h5bp/auth.conf;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://my_app;
}
access_log /var/log/nginx/example.com/access.log;
error_log /var/log/nginx/example.com/error.log;
charset utf-8;
error_page 404 /404.html;
error_page 502 503 @maintenance;
if (-f /srv/example.com/shared/maintenance.txt) {
return 503;
}
location @maintenance {
root /srv/maintenance;
rewrite ^(.*)$ /index.html break;
}
}
basic.conf
is from here: https://github.com/h5bp/server-configs-nginx/tree/master/h5bp
auth.conf
is only HTTP simple authentication.
Nginx log shows lines like this:
2018/03/12 11:48:32 [error] 9402#9402: *16285 open() "/srv/example.com/current/public/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--fe2fe760c83020f37a9fe8f78bcb4fc958744008/test-powerpoint-document.pptx" failed (2: No such file or directory), client: xxx.xx.xxx.xx, server: example.com, request: "GET /rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--fe2fe760c83020f37a9fe8f78bcb4fc958744008/test-powerpoint-document.pptx?disposition=upload HTTP/1.1", host: "example.com"
What am I missing?
Upvotes: 0
Views: 1478
Reputation: 360
In case anyone stumbles into the same issue, I fixed my case by commenting out the following:
# h5bp/location/expires.conf
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ {
access_log off;
add_header Cache-Control "max-age=2592000";
}
Now all images display and attachments download without any issue.
Upvotes: 1