# Trilium搭建同步服务器+域名访问

> [Trilium搭建同步服务器+域名访问](https://www.ftls.xyz/posts/80f7f39e/)
> Penned by [恐咖兵糖](https://www.ftls.xyz/) on 2021-02-15


Trilium搭建同步服务器+域名访问

Trilium搭建同步服务器，并且实现域名访问

<!--more-->
## 基本信息

文件名：trilium-linux-x64-server-0.45.9.tar.xz

## 安装指令

```sh

npm -v

6.14.10

node -v

v14.15.3

cd /home/trilium/trilium-linux-x64-server/

npm install

./trilium.sh

```

使用Ctrl+C退出进程，根据日志进行调试。

## 配置文件

此外还需配置config-sample.ini，这里我只修改了端口。

```

[General]

# Instance name can be used to distinguish between different instances using backend api.getInstanceName()

instanceName=kkbt

# set to true to allow using Trilium without authentication (makes sense for server build only, desktop build doesn't need password)

noAuthentication=false

# set to true to disable backups (e.g. because of limited space on server)

noBackup=false

# Disable automatically generating desktop icon

# noDesktopIcon=true

[Network]

# host setting is relevant only for web deployments - set the host on which the server will listen

# host=0.0.0.0

# port setting is relevant only for web deployments, desktop builds run on a fixed port (changeable with TRILIUM_PORT environment variable)

port=20202

#这里我只修改了端口

# true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure).

https=false

# path to certificate (run "bash bin/generate-cert.sh" to generate self-signed certificate). Relevant only if https=true

certPath=

keyPath=

```

这时，访问ip+port可以访问Trilium。比如访问`192.168.0.1:20202`。

## 后台运行

没有问题之后，把Trilium加入nohup,并让其在后台运行。nohup 为不挂断的运行（即使是ssh退出之后），末尾 & 为后台运行，即运行后终端能够接收任何输入。`>Trilium.log 2>&1`是将运行log记录到Trilium.log。

```

nohup ./trilium.sh >Trilium.log 2>&1 &

```

如果想要停止进程可以使用

```

netstat -anp |grep 20202

```

查看使用端口20202的进程

![da392424318f61c56995c3ec16550bb4.png](https://cdn.ftls.xyz/images/2021/12/H6cl.png)

使用

```

kill -9 23081

```

结束进程。

## 域名访问

可以配合宝塔的网站功能使用域名访问。宝塔版本：7.5.1

**注意**：使用宝塔需要在安全设置里开放20202端口（或者你使用的端口）。

1. 宝塔新建网站

2. 添加反向代理

3. 修改宝塔反向代理默认配置

图：添加的反向代理

  ![cad0a01a55134877321f24f2ff352e81.png](https://cdn.ftls.xyz/images/2021/12/HVA3.png)

注意：如果使用默认的反向代理，会出现新建笔记不会自动打开，需要刷新网页之后才能看到。

宝塔网站反向代理配置如下,这份配置来自于Trilium GIthub Wiki

```

location / {

  proxy_pass http://localhost:20202/;

  proxy_http_version 1.1;

  proxy_set_header Upgrade $http_upgrade;

  proxy_set_header Connection 'upgrade';

  proxy_set_header Host $host;

  proxy_cache_bypass $http_upgrade;

}

```

  访问`abc.com`即可看到Trilium服务。

  ![d56d9be6bcb4b7e79c7edbe5d0167e27.png](https://cdn.ftls.xyz/images/2021/12/Hmxt.png)

## 成果

![58e6dcfe5889f206d0a8afaaf5061dc4.png](https://cdn.ftls.xyz/images/2021/12/HLpG.png)

## 其他

在配置结束后，我关闭了ip访问端口20202的设置。在此之后可以使用域名的同步和访问。

![d37906aa516fafbd58cd062ee1dc047a.png](https://cdn.ftls.xyz/images/2021/12/Hb37.png)