|
| 1 | +--- |
| 2 | +title: Create a custom DNS alias by setting up a reverse proxy |
| 3 | +description: Learn how to set up a custom DNS alias for your instance using a reverse proxy |
| 4 | +date: 2025-05-16 |
| 5 | +tags: ['Server Admin', 'Security and Authentication'] |
| 6 | +keywords: ['custom DNS alias', 'DNS'] |
| 7 | +hide_title: true |
| 8 | +--- |
| 9 | + |
| 10 | +{frontMatter.description} |
| 11 | +{/* truncate */} |
| 12 | + |
| 13 | +<br/> |
| 14 | +<br/> |
| 15 | +# Custom DNS alias by setting up reverse proxy {#custom-dns-alias} |
| 16 | + |
| 17 | +> In this knowledgebase article, we will walk you through how you can set up a |
| 18 | +custom DNS alias for your ClickHouse Cloud instance through the use of a reverse |
| 19 | +proxy such as Nginx for ClickHouse native client. |
| 20 | + |
| 21 | +## Create a self-signed certificate {#create-certificate} |
| 22 | + |
| 23 | +:::note |
| 24 | +This step is not needed if you are using signed certificates. |
| 25 | +::: |
| 26 | + |
| 27 | +Create a self-signed certificate with the domain name of your choice. |
| 28 | +In this example we will use a domain name `xyz-customdomain.com` and |
| 29 | +create a certificate called `MyCertificate.crt`. Refer to ["Create SSL certificates"](/guides/sre/configuring-ssl#2-create-ssl-certificates) |
| 30 | +for further details. |
| 31 | + |
| 32 | +Add the certificate to `/etc/clickhouse-client/config.xml`: |
| 33 | + |
| 34 | +```yaml |
| 35 | +<clickhouse> |
| 36 | + <openSSL> |
| 37 | + <client> |
| 38 | + <loadDefaultCAFile>false</loadDefaultCAFile> |
| 39 | + # highlight-next-line |
| 40 | + <caConfig>/etc/ssl/certs/MyCertificate.crt</caConfig> |
| 41 | + <cacheSessions>true</cacheSessions> |
| 42 | + <disableProtocols>sslv2,sslv3</disableProtocols> |
| 43 | + <preferServerCiphers>true</preferServerCiphers> |
| 44 | + <invalidCertificateHandler> |
| 45 | + <name>RejectCertificateHandler</name> |
| 46 | + </invalidCertificateHandler> |
| 47 | + </client> |
| 48 | + </openSSL> |
| 49 | +</clickhouse> |
| 50 | +``` |
| 51 | + |
| 52 | +## Update Nginx configuration {#update-nginx-config} |
| 53 | + |
| 54 | +Add the following in your `nginx.conf` file: |
| 55 | + |
| 56 | +```text |
| 57 | +proxy_ssl_name xyz.us-west-2.aws.clickhouse.cloud; |
| 58 | +proxy_ssl_server_name on; |
| 59 | +``` |
| 60 | + |
| 61 | +```text |
| 62 | +stream { |
| 63 | + upstream stream_backend { |
| 64 | + server xyz.us-west-2.aws.clickhouse.cloud:9440; |
| 65 | + } |
| 66 | +
|
| 67 | + server { |
| 68 | + listen 9440 ssl; |
| 69 | + proxy_pass stream_backend; |
| 70 | +
|
| 71 | + ssl_certificate /etc/ssl/certs/MyCertificate.crt; |
| 72 | + ssl_certificate_key /etc/ssl/certs/MyKey.key; |
| 73 | + ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; |
| 74 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 75 | + ssl_session_cache shared:SSL:20m; |
| 76 | + ssl_session_timeout 4h; |
| 77 | + ssl_handshake_timeout 30s; |
| 78 | + proxy_ssl on; |
| 79 | + proxy_ssl_trusted_certificate /etc/ssl/certs/isrgrootx1.pem; |
| 80 | + proxy_ssl_session_reuse on; |
| 81 | + proxy_ssl_verify on; |
| 82 | + #highlight-next-line |
| 83 | + proxy_ssl_name xyz.us-west-2.aws.clickhouse.cloud; |
| 84 | + #highlight-next-line |
| 85 | + proxy_ssl_server_name on; |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Where `isrgrootx1.pem` is the root certificate for ClickHouse Cloud which you |
| 91 | +can download [here](https://letsencrypt.org/certs/isrgrootx1.pem). |
| 92 | + |
| 93 | +## Update hosts file {#update-hosts-file} |
| 94 | + |
| 95 | +:::note |
| 96 | +The following step is not needed if you are using your own domain controllers |
| 97 | +::: |
| 98 | + |
| 99 | +Add the following to your `/etc/hosts` file on the Nginx server: |
| 100 | + |
| 101 | +```text title='/etc/hosts' |
| 102 | +127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
| 103 | +::1 localhost6 localhost6.localdomain6 |
| 104 | +10.X.Y.Z xyz-customdomain.com |
| 105 | +``` |
| 106 | + |
| 107 | +Where `10.X.Y.Z` is the IP address of your specific Nginx box. |
| 108 | + |
| 109 | +## Connect to Cloud using alias {#connect-to-cloud-using-alias} |
| 110 | + |
| 111 | +You are now ready to connect using your custom alias: |
| 112 | + |
| 113 | +```bash |
| 114 | +clickhouse-client --host xyz.customdomain.com --secure --password 'xxxxxxx' |
| 115 | +ClickHouse client version 23.12.1.428 (official build). |
| 116 | +Connecting to xyz.customdomain.com:9440 as user default. |
| 117 | +Connected to ClickHouse server version 23.9.2. |
| 118 | + |
| 119 | +clickhouse-cloud :) |
| 120 | +``` |
0 commit comments