2024年6月17日月曜日

Cloudbeaver を nginx で動作させる方法

Cloudbeaver を nginx で動作させる方法

概要

rootURI を編集します
設定ファイルを置くパスがポイントです

環境

  • Ubuntu 22.04
  • docker 26.1.1
  • dbeaver 24.1.0
  • MySQL 8.0.36

dbeaver 用 compose.yaml

/opt/cloudbeaver/conf/cloudbeaver.conf に設定ファイルを配置します
dbeaver は 192.168.0.100:8978 で動作します

services:
  dbeaver:
    image: dbeaver/cloudbeaver:24.1.0
    volumes:
      - type: volume
        source: dbeaver
        target: /opt/cloudbeaver/workspace
      - type: bind
        source: /home/user01/work/cloudbeaver.conf
        target: /opt/cloudbeaver/conf/cloudbeaver.conf
    ports:
      - 8978:8978
    restart: always

volumes:
  dbeaver:

cloudbeaver.conf

少し長いですがすべて掲載しています
変更するのは冒頭の rootURI の部分だけです
それ以外はすべてデフォルトの設定です

今回は /dbeaver で受けます

{
    server: {
        serverPort: 8978,

        workspaceLocation: "workspace",
        contentRoot: "web",
        driversLocation: "drivers",

        sslConfigurationPath:"${CLOUDBEAVER_SSL_CONF_PATH:workspace/.data/ssl-config.xml}",

        rootURI: "/dbeaver",
        serviceURI: "/api/",

        productSettings: {
            # Global properties
            core.theming.theme: 'light',
            core.localization.localization: 'en',
            plugin.sql-editor.autoSave: true,
            plugin.sql-editor.disabled: false,
            # max size of the file that can be uploaded to the editor (in kilobytes)
            plugin.sql-editor.maxFileSize: 10240,
            plugin.log-viewer.disabled: false,
            plugin.log-viewer.logBatchSize: 1000,
            plugin.log-viewer.maxFailedRequests: 3,
            plugin.log-viewer.maxLogRecords: 2000,
            plugin.log-viewer.refreshTimeout: 3000,
            sql.proposals.insert.table.alias: PLAIN
        },

        expireSessionAfterPeriod: 1800000,

        develMode: false,

        enableSecurityManager: false,

        sm: {
            enableBruteForceProtection: "${CLOUDBEAVER_BRUTE_FORCE_PROTECTION_ENABLED:true}",
            maxFailedLogin: "${CLOUDBEAVER_MAX_FAILED_LOGINS:10}",
            minimumLoginTimeout: "${CLOUDBEAVER_MINIMUM_LOGIN_TIMEOUT:1}",
            blockLoginPeriod: "${CLOUDBEAVER_BLOCK_PERIOD:300}",
            passwordPolicy: {
                minLength: "${CLOUDBEAVER_POLICY_MIN_LENGTH:8}",
                requireMixedCase: "${CLOUDBEAVER_POLICY_REQUIRE_MIXED_CASE:true}",
                minNumberCount: "${CLOUDBEAVER_POLICY_MIN_NUMBER_COUNT:1}",
                minSymbolCount: "${CLOUDBEAVER_POLICY_MIN_SYMBOL_COUNT:0}"
            }
        },

        database: {
            driver: "h2_embedded_v2",
            url: "jdbc:h2:${workspace}/.data/cb.h2v2.dat",
            initialDataConfiguration: "conf/initial-data.conf",
            pool: {
                minIdleConnections: 4,
                maxIdleConnections: 10,
                maxConnections: 100,
                validationQuery: "SELECT 1"
            },
            backupEnabled: "${CLOUDBEAVER_DB_BACKUP_ENABLED:true}"
        }

    },
    app: {
        anonymousAccessEnabled: true,
        anonymousUserRole: "user",
        defaultUserTeam: "user",
        grantConnectionsAccessToAnonymousTeam: false,
        supportsCustomConnections: false,
        showReadOnlyConnectionInfo: false,
        systemVariablesResolvingEnabled: "${CLOUDBEAVER_SYSTEM_VARIABLES_RESOLVING_ENABLED:false}",

        forwardProxy: false,

        publicCredentialsSaveEnabled: true,
        adminCredentialsSaveEnabled: true,

        resourceManagerEnabled: true,

        resourceQuotas: {
            dataExportFileSizeLimit: 10000000,
            resourceManagerFileSizeLimit: 500000,
            sqlMaxRunningQueries: 100,
            sqlResultSetRowsLimit: 100000,
            sqlResultSetMemoryLimit: 2000000,
            sqlTextPreviewMaxLength: 4096,
            sqlBinaryPreviewMaxLength: 261120
        },
        enabledAuthProviders: [
            "local"
        ],

        disabledDrivers: [
            "sqlite:sqlite_jdbc",
            "h2:h2_embedded",
            "h2:h2_embedded_v2",
            "clickhouse:yandex_clickhouse"
        ],
        disabledBetaFeatures: [

        ]

    }

}

nginx.conf

location /dbeaver/ を定義します
proxy_set_header 系はそのままコピペで OK です

location = /dbeaver はリダイレクト用でなぜか自動でブラウザがリダイレクトしてくれないケースがあるので明示しておきます
末尾のスラッシュがない場合にスラッシュのある URI に移動させます

upstream dbeaver {
    server 192.168.0.100:8978;
}


server {
    listen 80;
    server_name my_nginx;

    location = /dbeaver {
        return 302 /dbeaver/;
    }

    location /dbeaver/ {
        proxy_pass http://dbeaver;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

動作確認

これで nginx と dbeaver を起動させ nginxのアドレス/dbeaver にアクセスすると画面が表示されます

最後に

DBeaver を nginx 配下で動作させる方法を紹介しました
サブディレクトリを指定する場合は dbeaver 側の rootURI も変更する必要があります

参考サイト

0 件のコメント:

コメントを投稿