Nginx 404 for /rails/active_storage/blobs/*filename(extensio



下面是我的AWS NGINX配置文件。当我尝试打开文件时,上传后,我在新的 rails 应用程序中使用带有活动存储的富文本,它在生产中给了我 404 错误,在开发中它工作得很好。

files:
/etc/nginx/conf.d/proxy.conf:
mode: "000755"
owner: root
group: root
content: |
upstream backend {
server unix:///var/run/puma/my_app.sock;
}
log_format logd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
server_name _ localhost; # need to listen to localhost for worker tier
return 301 https://$host$request_uri;
}
server {
listen 443;
charset UTF-8;
server_name _ localhost; # need to listen to localhost for worker tier

root /var/app/current/public;    
# try_files $uri/index.html $uri /deploy/$uri /deploy/$uri.html /deploy/$uri.js @puma;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
if ($time_iso8601 ~ "^(d{4})-(d{2})-(d{2})T(d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log  /var/log/nginx/access.log  main;
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour logd;

# 413 Request Entity Too Large
client_max_body_size 50M;
large_client_header_buffers 8 32k;
location / {
try_files $uri /deploy/$uri /deploy/$uri.html /deploy/$uri.js @puma;
}

location @puma{
proxy_pass http://backend;
# proxy_pass http://backend; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_redirect off;
#break;
}
location /assets {
alias /var/app/current/public/assets;
allow all;
}
location ~ .(png|jpg|jpeg|gif|ico|html|woff|woff2|ttf|svg|eot|otf|pdf)$ {
expires max;
access_log off;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
}
location ~* .(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc|pdf)$ {
access_log off;
add_header Cache-Control "max-age=2592000";
}

if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}

每当我打开带有文件扩展名的链接时,它都会向我显示 404 错误,但如果我打开没有文件扩展名的相同链接,它可以在没有文件扩展名的情况下使用链接。不知道我做错了什么,请帮忙

尝试在 Nginx 中禁用以下块,这可能会修复它

location ~ .(png|jpg|jpeg|gif|ico|html|woff|woff2|ttf|svg|eot|otf|pdf)$ {
gzip_static on;
gzip on;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_vary on;
gzip_proxied any;
expires max;
access_log off;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
}
location ~* .(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc|pdf)$ {
access_log off;
add_header Cache-Control "max-age=2592000";
}

最新更新