我的页面上的一些图像在 Safari 中会丢失,控制台Failed to load resource: The network connection was lost.
图像服务器中的消息是不同的域,我可以通过在其他浏览器选项卡中粘贴 URL 正确看到图像。
我找到了这个 https://gist.github.com/voronianski/791ef517c5392d7ce5fb但我不知道如何解决?
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
reset_timedout_connection on;
send_timeout 2;
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
....
server {
listen 80;
server_name domain www.domain;
access_log /var/log/nginx/domain.access.log;
location /robots.txt {
alias /var/www/html/domain/app/robots.txt;
}
location ~ ^/(images/|javascripts/|stylesheets/|fonts) {
root /var/www/html/domain/app/assets;
access_log off;
expires max;
}
location / {
set $fixed_destination $http_destination;
if ( $http_destination ~* ^https(.*)$ )
{
set $fixed_destination http$1;
}
proxy_pass http://127.00.0.1:8005/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Destination $fixed_destination;
client_max_body_size 50M;
client_body_buffer_size 512k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
sub.domain 下的图片服务器
server {
listen 80;
server_name sub.domain www.sub.domain;
access_log /var/log/nginx/sub.domain.access.log;
location /robots.txt {
alias /var/www/html/sub.domain/app/robots.txt;
}
location ~ ^/(images/|javascripts/|stylesheets/|fonts) {
root /var/www/html/sub.domain/app/assets;
access_log off;
expires max;
}
location / {
set $fixed_destination $http_destination;
if ( $http_destination ~* ^https(.*)$ )
{
set $fixed_destination http$1;
}
proxy_pass http://127.00.0.1:8006/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Destination $fixed_destination;
client_max_body_size 50M;
client_body_buffer_size 512k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
更新
我将图像文件夹复制到同一个域下进行测试,但仍然出现相同的错误,我以不同的分辨率存储图像,因此我测试是否选择所有较小的尺寸并可以工作。如何解决这个问题?我错过了什么吗?我应该增加keepalive_timeout
什么吗?
我通过将send_timeout
2 增加到 60 来解决这个问题,它可以正确获取所有图像。增加 可以吗send_timeout
?正确的解决方法是什么?