User-friendly error pages from Varnish

前端 未结 4 1894
说谎
说谎 2021-02-04 07:49

We are using Varnish at the front of Plone. In the case Plone goes down or serves an internal error we\'d like to show a user-friendly static HTML page which some CSS styling +

4条回答
  •  梦如初夏
    2021-02-04 08:00

    If you rather prefer to deliver an error page from a static file, you can override vcl_error() with a bit of C-code:

    sub vcl_error {
        set obj.http.Content-Type = "text/html; charset=utf-8";
    
        C{
            #include 
            #include 
    
            FILE * pFile;
            char content [100];
            char page [10240];
            char fname [50];
    
            page[0] = '\0';
            sprintf(fname, "/var/www/error/index.html", VRT_r_obj_status(sp));
    
            pFile = fopen(fname, "r");
            while (fgets(content, 100, pFile)) {
                strcat(page, content);
            }
            fclose(pFile);
            VRT_synth_page(sp, 0, page, "", vrt_magic_string_end);
    
            return (deliver);
        }C
    }
    

提交回复
热议问题