以下是我的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;
}
}
[每当我打开Link with file extension时,它就会显示404错误,但是如果我打开相同的链接而没有文件扩展名,则它会正常工作Link without file extension。不确定我在做什么错,请帮助
尝试在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";
}