4

One of my WordPress sites has a lot of static images (think at least 20 per page) and after I enable HTTP/2, the images in the lower part start to appear as broken (crossed out, like in images with dead links). Nothing wrong shows up in error.log file, but Chrome 53 says like this in the console:

Failed to load resource: net::ERR_SPDY_PROTOCOL_ERROR

I tried messing with client_max_body_size but that was no luck.

edit: this is my nginx.conf:

load_module /usr/local/libexec/nginx/ngx_mail_module.so;
load_module /usr/local/libexec/nginx/ngx_stream_module.so;
user  www;
worker_processes 4;
error_log  /var/log/nginx/error.log  info;

events {
        worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 0;
    large_client_header_buffers 2 1k;
    client_body_timeout 12;
    send_timeout 10;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip off;
    charset UTF-8;

    server {
        listen       80;
        server_name manuth.life www.manuth.life;
        server_tokens off;
        return 301 https://$server_name$request_uri; #redirects to HTTPS
        root   /usr/local/www/nginx/manuth.life;
        index index.php index.html index.htm;
        access_log /var/log/nginx/manuth.life.access.log;
        error_log /var/log/nginx/manuth.life.error.log;

        error_page      500 502 503 504  /50x.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
    }

    server {
        listen       443 ssl http2;
        server_name  manuth.life www.manuth.life;
        server_tokens off;
        root   /usr/local/www/nginx/manuth.life;
        index index.php index.html index.htm;
        access_log /var/log/nginx/manuth.life.access.log;
        error_log /var/log/nginx/manuth.life.error.log;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

        # strict SSL settings
        ssl_certificate /usr/local/etc/letsencrypt/live/manuth.life/fullchain.pem;
        ssl_certificate_key /usr/local/etc/letsencrypt/live/manuth.life/privkey.pem;

        ssl_session_timeout 5m;
        ssl_protocols TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
        ssl_ecdh_curve secp384r1; #
        ssl_session_cache builtin:1000 shared:SSL:10m;
        ssl_session_tickets off;
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_dhparam /usr/local/etc/ssl/dhparam.pem;
        resolver 8.8.8.8 8.8.4.4 valid=300s;
        resolver_timeout 10s;
        add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;

        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }

    }

}

Manuth Chek
  • 402
  • 2
  • 6
  • 16
  • What do you mean by "creates a very long URL"? And what is the URL requested by the browser? – Tero Kilkanen Oct 06 '16 at 11:13
  • @TeroKilkanen I got confused with another line in error.log thanks to my poor eyes... Basically each page would display the first probably 10 images correctly, but every image below is crossed out. Ctrl+U shows nothing wrong in HTML and the only error I could find is this `ERR_SPDY_PROTOCOL_ERROR` in Chrome's console. I copied the links of the 'broken' image and opened it directly, and it worked too. – Manuth Chek Oct 06 '16 at 11:18
  • Which version of nginx are you using? – Michael Hampton Oct 07 '16 at 20:57
  • @MichaelHampton I'm using 1.10.1 from FreeBSD's pkg, not from source. HTTPV2 is already enabled anyway. – Manuth Chek Oct 08 '16 at 02:12

2 Answers2

1

This seems to be a problem with Chrome 53. I'm using Chrome 54 and I no longer see this issue. In fact the speed just flies! (on local network, that is)

Manuth Chek
  • 402
  • 2
  • 6
  • 16
  • If this problem is solved, please mark it as solved by clicking the check mark to the left of the answer so that it turns green. – Michael Hampton Mar 09 '18 at 17:05
0

You're getting SPDY errors, which is a predecessor of HTTP2. HTTP2 isn't built into Nginx by default, you have to build Nginx yourself (documentation link that says this, tutorial link for the build). Building Nginx is pretty easy. Some distributions may build http/2 in.

Once you've gotten Nginx with HTTP/2 support built in, as people have save, you need to add the http2 directive to your listen command.

listen 443 ssl http2;

If this doesn't work you'll need to post your full, accurate configuration, plus a link to the website that's not working properly. We can't diagnose what we can't see.

Tim
  • 31,888
  • 7
  • 52
  • 78
  • You can try this: https://manuth.life/soshi/yoona/concerts/2016/161001-busan-one-asia-festival Also HTTP/2 is already in my version. – Manuth Chek Oct 08 '16 at 02:13
  • Something screwy is going on. On a webpagetest.org test I can see it's super slow to download images, which incidentally are WAY too large. But they do download. Some simple compression will reduce your image size by 80% or more and may help with the problem. If you reduce the image dimensions, which you should as they're too big for a web browser vertically, you could achieve 95% size reduction. – Tim Oct 08 '16 at 02:26
  • Well, the point of the site is to serve high-res images like that. Is it safe to enable gzip compression only on the directory that contains the images? I disabled it since the site is HTTPS only and I've read that it's not safe to enable it with HTTPS. – Manuth Chek Oct 08 '16 at 02:29
  • Gzip won't help images, it only helps web pages, and tends to be automatically disabled for images. You can make the image files smaller but look just as good very easily, for example with https://tinyjpg.com/ . I don't know if it'll solve your problem but I suspect it will help. Also, use a CDN like CloudFlare, it will serve the images much faster than your web server. – Tim Oct 08 '16 at 03:10
  • Looks like I need to roll back to HTTP 1.1 then. I have too many images to downsize (and the point is to serve high-res images anyway), plus the total size would be too large. This problem seems to be only on Chrome, at least on the version 53 that I'm using. – Manuth Chek Oct 08 '16 at 03:19
  • It might be http2, it might be something else. Nothing else stands out to me as a problem. If it works perfectly on HTTP1.1 then I'd probably stick with it for now. – Tim Oct 08 '16 at 04:15
  • Chrome 54 appears to have fixed this issue. – Manuth Chek Oct 14 '16 at 12:45