weixin_39695672
weixin_39695672
2021-01-12 11:44

Fix font Roboto css url relative

Currently the font roboto css style url url has a leading /, which results font access url from root path. Even with a --path_prefix=/path/to/tensorboard/, the font url is still from root path, unchanged. e.g, http://host:6006/font-roboto/d-6IYplOFocCacKzxwXSOJBw1xU1rKptJj_0jans920.woff2. Thus, the tensorboard from http://host:6006/path/to/tensorboard/ gives 404 errors with the font url.

The CSS codes are as below, the leading / in url(/font-roboto/ needs to be stripped to render from relative path http://host:6006/path/to/tensorboard/font-roboto/d-6IYplOFocCacKzxwXSOJBw1xU1rKptJj_0jans920.woff2.

css
-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: local('Roboto'), local('Roboto-Regular'), url(/font-roboto/uYECMKoHcO9x1wdmbyHIm3-_kf6ByYO6CLYdB4HQE-Y.woff2) format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

该提问来源于开源项目:tensorflow/tensorboard

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39716264 weixin_39716264 3月前

    This change is probably the right thing to do. But before I approve, might I ask the following?

    You've configured your environment to use --path_prefix=/path/to/tensorboard/. Maybe alongside NGINX or something. When you forward requests to TensorBoard, do you have it hard-coded to only forward requests for the / path? Or do you forward for that entire prefix?

    点赞 评论 复制链接分享
  • weixin_39695672 weixin_39695672 3月前

    Actually in my nginx file, I don't use --prefix-path, I just forward all / path to a sub directory to domain. The config is as follows:

    nginx
    location /tensorboard/
    {
        proxy_pass http://127.0.0.1:6006/;
    }
    

    In this case the final requests url has a base path, but the font requests from browser always request from root path. A workaroud is to add another rule to nginx, and the config becomes

    nginx
    location /tensorboard/
    {
        proxy_pass http://127.0.0.1:6006/;
    }
    location /font-roboto/
    {
        proxy_pass http://127.0.0.1:6006/font-roboto/;
    }
    

    However, this messes up my root configuration.

    The font requests from browser always request from root http://host/font-roboto/. If there's a prefix path (either from --path_prefix or other configurations), extra efforts must be done to process the font requests. For standalong tensorboard, running tensorboard --path_prefix=/abc/ --logdir=logs and requesting http://localhost:6006/abc/ always give 404 errors.

    点赞 评论 复制链接分享
  • weixin_39716264 weixin_39716264 3月前

    I'm 99% sure rewrite can do the job:

    nginx
    server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
    
      location /tensorboard/ {
        rewrite /tensorboard/(.*) /$1  break;
        proxy_http_version 1.1;
        proxy_pass http://127.0.0.1:6006;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
      }
    }
    

    If not, let me know and I'll re-open. Further note: if there's a syntax error above, let me know so I can edit for future searchability.

    点赞 评论 复制链接分享
  • weixin_39716264 weixin_39716264 3月前

    Please note that we might also want to consider deleting the --path_prefix flag entirely, since software like NGINX is capable of transparently rewriting URLs as part of the reverse proxying process.

    点赞 评论 复制链接分享

为你推荐