修改docker部署的draw.io的默认分享地址

2025-06-14阅读(150)评论(0)牵着狗狗看MM

苏州实时公交查询

本地化部署draw.io后,选择 文件>导出为>URL

默认的分享链接为 https://viewer.diagrams.net 而不是本地的URL或者你配置的自己的域名

修改分享URL的方法

参考https://github.com/jgraph/docker-drawio/blob/dev/main/docker-entrypoint.sh 这个文件

文件中第一部分就是官网文档上的一些变量

#!/bin/bash
#set -e

LETS_ENCRYPT_ENABLED=${LETS_ENCRYPT_ENABLED:-false}
PUBLIC_DNS=${PUBLIC_DNS:-'draw.example.com'}
ORGANISATION_UNIT=${ORGANISATION_UNIT:-'Cloud Native Application'}
ORGANISATION=${ORGANISATION:-'example inc'}
CITY=${CITY:-'Paris'}
STATE=${STATE:-'Paris'}
COUNTRY_CODE=${COUNTRY_CODE:-'FR'}
KEYSTORE_PASS=${KEYSTORE_PASS:-'V3ry1nS3cur3P4ssw0rd'}
KEY_PASS=${KEY_PASS:-$KEYSTORE_PASS}

还有一些全局变量

#Overrides of global vars need to be pre-loaded
if [[ "${DRAWIO_SELF_CONTAINED}" ]]; then
    echo "window.EXPORT_URL = '/service/0'; //This points to ExportProxyServlet which uses the local export server at port 8000. This proxy configuration allows https requests to the export server via Tomcat." >> $CATALINA_HOME/webapps/draw/js/PreConfig.js
    echo "window.PLANT_URL = '/service/1';" >> $CATALINA_HOME/webapps/draw/js/PreConfig.js
elif [[ "${EXPORT_URL}" ]]; then
    echo "window.EXPORT_URL = '/service/0';" >> $CATALINA_HOME/webapps/draw/js/PreConfig.js
fi
#DRAWIO_SERVER_URL is the new URL of the deployment, e.g. https://www.example.com/drawio/
#DRAWIO_BASE_URL is still used by viewer, lightbox and embed. For backwards compatibility, DRAWIO_SERVER_URL is set to DRAWIO_BASE_URL if not specified.
# Strip trailing slash from DRAWIO_SERVER_URL to get base URL
if [[ -n "$DRAWIO_SERVER_URL" ]]; then
  DRAWIO_BASE_URL_VALUE="${DRAWIO_SERVER_URL%/}"
else
  DRAWIO_BASE_URL_VALUE="http://localhost:8080"
fi

这些全局变量会覆盖PreConfig.js中的变量

查看说明,就找到了我们想要修改的变量DRAWIO_BASE_URLDRAWIO_LIGHTBOX_URL

在docker的启动命令中增加这2个变量的配置即可

以官方的默认启动命令为例(注意:自己的域名后面不要加斜杠)

docker run -it --rm --name="draw" -p 8080:8080 -p 8443:8443 -e DRAWIO_BASE_URL=https://www.yourDomain.com -e DRAWIO_LIGHTBOX_URL=https://www.yourDomain.com jgraph/drawio

启动后,再查看导出的分享链接,就变成你自己的域名了

 

设置中文

设置中文需要注意2个地方

1.分享的设置为中文

上面的分享启动命令需调整为如下(注意等号后面的双引号):

docker run -it --rm --name="draw" -p 8080:8080 -p 8443:8443 -e DRAWIO_BASE_URL="https://www.yourDomain.com/?lang=zh" -e DRAWIO_LIGHTBOX_URL="https://www.yourDomain.com/?lang=zh" jgraph/drawio

 

2.默认打开时的设置为中文,在nginx做个重定向,判断有没有参数,没有参数则跳转

server {
  listen 80;
  server_name localhost;

  location / {
    # 检查请求是否没有带参数
    if ($args = "") {
      return 301 $scheme://$host$request_uri?lang=zh;
    }

   if ($args !~* "(^|&)lang=zh(&|$)") {
        return 301 $scheme://$host$request_uri&lang=zh;
   }

    root   /usr/share/nginx/html;
    index  index.html;
    try_files $uri $uri/ /index.html;
  }
}

 

赞(0)
转载请注明来源:Web前端(W3Cways.com) - Web前端学习之路 » 修改docker部署的draw.io的默认分享地址
分享到: 更多 (0)