# Selfhost Discourse in Mainland China Under the GFW

**URL:** https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038
**Category:** Self-hosting
**Tags:** hosting
**Created:** [January 14, 2025, 10:23am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038 "2025-01-14T10:23:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![J\_J1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j_j1/32/478367_2.png) [@J\_J1](https://meta.discourse.org/u/J_J1)
#### Post date: [January 14, 2025, 10:23am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/1 "2025-01-14T10:23:32Z")

</div>

## Background

The self-hosting documentation for Discourse is excellent, and the installation process went smoothly. However, I encountered issues when deploying my server in mainland China, behind the [Great Firewall](https://en.wikipedia.org/wiki/Great_Firewall).

## Issue

Whenever I run `./launcher rebuild app`, the process fails due to network restrictions. Below are the key error messages:

```bash
I, [2025-01-14T10:21:45.402169 #1] INFO -- : Scope: all 17 workspace projects
Lockfile is up to date, resolution step is skipped
Progress: resolved 1, reused 0, downloaded 0, added 0
Packages: +87 -15
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Progress: resolved 87, reused 46, downloaded 0, added 33
Progress: resolved 87, reused 46, downloaded 18, added 53
Progress: resolved 87, reused 46, downloaded 25, added 61
Progress: resolved 87, reused 46, downloaded 29, added 66
Progress: resolved 87, reused 46, downloaded 30, added 67
Progress: resolved 87, reused 46, downloaded 30, added 68
 WARN GET https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.9.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/lefthook-linux-x64/-/lefthook-linux-x64-1.10.4.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/@embroider/compat/-/compat-3.8.0.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.7.2.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/ace-builds/-/ace-builds-1.37.4.tgz error (ECONNRESET). Will retry in 10 seconds. 2 retries left.
 WARN GET https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.9.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 WARN GET https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 WARN GET https://registry.npmjs.org/lefthook-linux-x64/-/lefthook-linux-x64-1.10.4.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 WARN GET https://registry.npmjs.org/@embroider/compat/-/compat-3.8.0.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 WARN GET https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.7.2.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 WARN GET https://registry.npmjs.org/ace-builds/-/ace-builds-1.37.4.tgz error (ERR_SOCKET_TIMEOUT). Will retry in 1 minute. 1 retries left.
 ERR_SOCKET_TIMEOUT request to https://registry.npmjs.org/@embroider/compat/-/compat-3.8.0.tgz failed, reason: Socket timeout

FetchError: request to https://registry.npmjs.org/@embroider/compat/-/compat-3.8.0.tgz failed, reason: Socket timeout
    at ClientRequest.<anonymous> (/usr/lib/node_modules/pnpm/dist/pnpm.cjs:66979:18)
    at ClientRequest.emit (node:events:517:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:529:35)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

I, [2025-01-14T10:21:45.402602 #1] INFO -- : Terminating async processes
I, [2025-01-14T10:21:45.402652 #1] INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 39
107:signal-handler (1736850105) Received SIGTERM scheduling shutdown...
I, [2025-01-14T10:21:45.402684 #1] INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 107
2025-01-14 10:21:45.402 UTC [39] LOG: received fast shutdown request
2025-01-14 10:21:45.404 UTC [39] LOG: aborting any active transactions
2025-01-14 10:21:45.406 UTC [39] LOG: background worker "logical replication launcher" (PID 54) exited with exit code 1
2025-01-14 10:21:45.407 UTC [49] LOG: shutting down
2025-01-14 10:21:45.431 UTC [39] LOG: database system is shut down
107:M 14 Jan 2025 10:21:45.436 # User requested shutdown...
107:M 14 Jan 2025 10:21:45.436 * Saving the final RDB snapshot before exiting.
107:M 14 Jan 2025 10:21:45.441 * DB saved on disk
107:M 14 Jan 2025 10:21:45.441 # Redis is now ready to exit, bye bye...

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && if [-f yarn.lock]; then
  if [-d node_modules/.pnpm]; then
    echo "This version of Discourse uses yarn, but pnpm node_modules are preset. Cleaning up..."
    find ./node_modules ./app/assets/javascripts/*/node_modules -mindepth 1 -maxdepth 1 -exec rm -rf {} +
  fi
  su discourse -c 'yarn install --frozen-lockfile && yarn cache clean'
else
  su discourse -c 'CI=1 pnpm install --frozen-lockfile && pnpm prune'
fi failed with return #<Process::Status: pid 301 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"yarn", "cmd"=>["if [-f yarn.lock]; then\n if [-d node_modules/.pnpm]; then\n echo \"This version of Discourse uses yarn, but pnpm node_modules are preset. Cleaning up...\"\n find ./node_modules ./app/assets/javascripts/*/node_modules -mindepth 1 -maxdepth 1 -exec rm -rf {} +\n fi\n su discourse -c 'yarn install --frozen-lockfile && yarn cache clean'\nelse\n su discourse -c 'CI=1 pnpm install --frozen-lockfile && pnpm prune'\nfi"]}
bootstrap failed with exit code 1
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
58bc76b977b8eb7c806f0308caacabe389605c6242852e8f17c30076b728de67

```

It seems the failure is caused by the inability to fetch packages or dependencies (e.g., from GitHub or npm) due to network restrictions in mainland China.

## What I’ve Tried

**Using a Proxy** : I attempted to set up a proxy server using [Shell Clash](https://github.com/juewuy/ShellClash) and successfully accessed Google (which is typically inaccessible from mainland China). Here’s the test output:

```bash
root@lavm-hypge0pc5w:/var/discourse# sudo wget google.com
--2025-01-14 18:35:22-- http://google.com/
Resolving google.com (google.com)... 198.18.0.5
Connecting to google.com (google.com)|198.18.0.5|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2025-01-14 18:35:22-- http://www.google.com/
Resolving www.google.com (www.google.com)... 198.18.0.6
Connecting to www.google.com (www.google.com)|198.18.0.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.2’

index.html.2 [<=>] 19.38K --.-KB/s in 0.05s   

2025-01-14 18:35:22 (372 KB/s) - ‘index.html.2’ saved [19841]

root@lavm-hypge0pc5w:/var/discourse# 

```

However, after running `./launcher rebuild app`, I still get the same error as before.

## Questions

Is there any way to successfully deploy Discourse on a server located in mainland China?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [January 14, 2025, 11:15am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/2 "2025-01-14T11:15:28Z")

</div>

Hi 🙂

Have you looked at [🇨🇳 Discourse Official Install Guide | Discourse 云平台安装](https://meta.discourse.org/t/discourse-official-install-guide-discourse/197803)? It covers typical issues when installing Discourse in Mainland China.

---

<div class="post-metadata">

### Author: ![J\_J1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j_j1/32/478367_2.png) [@J\_J1](https://meta.discourse.org/u/J_J1)
#### Post date: [January 15, 2025, 3:22am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/3 "2025-01-15T03:22:41Z")

</div>

Yes, I’ve seen this post. It’s essentially a Chinese translation of [INSTALL-cloud.md](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md.)

---

<div class="post-metadata">

### Author: ![J\_J1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j_j1/32/478367_2.png) [@J\_J1](https://meta.discourse.org/u/J_J1)
#### Post date: [January 15, 2025, 3:25am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/4 "2025-01-15T03:25:55Z")

</div>

My issue was **resolved** by adding the following line to my `app.yaml` file:  
`- "templates/web.china.template.yml"`

If you’re facing a similar issue, you might find this article helpful: [Discourse Installation Guide](https://tom.moe/t/discourse/198).

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [January 15, 2025, 12:31pm UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/5 "2025-01-15T12:31:17Z")

</div>

> [@J\_J1](#):
>
> Yes, I’ve seen this post. It’s essentially a Chinese translation of [INSTALL-cloud.md](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md.)

It covers parts specific to China, such as the issue you faced:

> [@cn Discourse Official Install Guide | Discourse 云平台安装](https://meta.discourse.org/t/discourse-official-install-guide-discourse/197803/1):
>
> #### 国网络环境的优化
> 
> 如果你的云服务器在中国大陆，那你在执行 `./discourse-setup` 或者 `./launcher rebuild app` 的过程中很可能遇到一些网络问题。Discourse已经帮你写好了除了docker以外的镜像服务，只需要在你的 `containers/app.yml` 中的这里添加一行：
> 
> ```plaintext
> templates:
> - "templates/postgres.template.yml"
> - "templates/redis.template.yml"
> - "templates/web.template.yml"
> - "templates/web.china.template.yml" # 添加这一行，配置npm, rubygems等包管理器的镜像
> 
> ```
> 
> 即可解决。

---

<div class="post-metadata">

### Author: ![J\_J1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j_j1/32/478367_2.png) [@J\_J1](https://meta.discourse.org/u/J_J1)
#### Post date: [January 16, 2025, 6:25am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/6 "2025-01-16T06:25:36Z")

</div>

I totally missed that line. thanks a ton!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [February 15, 2025, 6:26am UTC](https://meta.discourse.org/t/selfhost-discourse-in-mainland-china-under-the-gfw/347038/7 "2025-02-15T06:26:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
