# 故障

## 使用 Outlook 配置 SMTP 不成功 <a href="#configuring-smtp-with-outlook-does-not-work" id="configuring-smtp-with-outlook-does-not-work"></a>

使用 Outlook 始终无法在 Vaultwarden 上配置成功，但我部署的官方 Bitwarden 使用 Outlook 配置  SMTP 完全正常。此故障可能和这个有关：[# 851](https://github.com/dani-garcia/vaultwarden/issues/851)

## 直接修改 `config.json` 文件不生效 <a href="#modifying-the-config-json-file-directly-does-not-work" id="modifying-the-config-json-file-directly-does-not-work"></a>

通过管理页面修改配置并保存后，会将配置参数写入 `config.json` 文件，但当通过直接编辑 `config.json` 文件配置参数后，管理页面无法读取修改后的配置参数。

**原因为只有在 Vaultwarden 容器启动时才会读取 `config.json` 文件**。修改 `config.json` 文件后要使功能生效，需要在修改 `config.json` 文件后重启 Vaultwarden 容器：

```shell
docker restart vaultwarden
```

## 日志记录的时间和系统时间不一致 <a href="#the-time-of-logging-and-the-system-time-do-not-match" id="the-time-of-logging-and-the-system-time-do-not-match"></a>

日志记录使用 UTC（全球标准时间），而中国使用时间为 UTC+8，比 UTC 推后 8小时。

在创建 Vaultwarden 容器时加上时区环境变量：

```systemd
-e TZ=Asia/Shanghai
```

## Fail2ban 不起作用 <a href="#fail2ban-not-work" id="fail2ban-not-work"></a>

先查看 Fail2ban 是否正常运行。如果正常运行，运行下面的命令后将显示 `Server replied: pong`：

```shell
sudo fail2ban-client ping
```

如果 Fail2ban 正常运行，可能的原因：

### 创建 Jail 文件时 Vaultwarden 日志记录文件的路径设置不正确 <a href="#incorrect-path-setting-when-creating-jail-file" id="incorrect-path-setting-when-creating-jail-file"></a>

### Vaultwarden 日志记录文件中记录项的时间和系统时间不一致 <a href="#the-time-of-the-log-entry-and-the-system-time-do-not-match" id="the-time-of-the-log-entry-and-the-system-time-do-not-match"></a>

**原因**：Vaultwarden 容器的时区与主机的时区不一致

**现象**：无论怎么测试，fail2ban.log 中看不到 ban IP 的记录

**解决**：在创建 Vaultwarden 容器时加上时区环境变量：`-e TZ = Asia/Shanghai`

### Fail2ban 的 iptables 封禁策略不正确 <a href="#fail2bans-iptables-blocking-policy-is-incorrect" id="fail2bans-iptables-blocking-policy-is-incorrect"></a>

**原因**：Fail2ban 默认的 iptables 封禁策略为 `REJECT--reject-with icmp-port-unreachable`，需要变更为 `DROP`

**现象**：`sudo iptables --list -n` 命令能看到被 ban 的 IP 记录，但封禁策略为 `REJECT`

**解决**：编辑 `/etc/fail2ban/action.d/iptables-common.conf` 文件，将封禁策略变更为 `DROP`

```bash
# 打开 iptables-common.conf 文件
sudo vi /etc/fail2ban/action.d/iptables-common.conf

# 注释掉这一行
blocktype = REJECT --reject-with icmp-port-unreachable

# 添加一行
blocktype = DROP

# 重启 Fail2ban
sudo systemctl restart fail2ban
```

## Let's Encrypt 证书未自动续期 <a href="#lets-encrypt-certificate-does-not-auto-renew" id="lets-encrypt-certificate-does-not-auto-renew"></a>

正常情况下，使用 LNMP 自带的 Let's Encrypt 生成的相应的证书（这里为 `vault.yourdomain.com`）会自动续期。

### Let's Encrypt 未自动续期的原因 <a href="#reasons-why-lets-encrypt-does-not-auto-renew" id="reasons-why-lets-encrypt-does-not-auto-renew"></a>

查看 Let's Encrypt 日志文件 `/usr/local/acme.sh/acme.sh.log`，发现如下错误记录：

> Verify error:Invalid response from <https://vault.yourdomain.com/.well-known/acme-challenge/QK1Gw-lJbi78GO5smcU1-Akkkm13UQbtLmVR073J2iI>

原因为我之前将 `vault.yourdomain.com.conf` 配置文件中的如下语句移除了，添加上即可：

<pre class="language-nginx"><code class="lang-nginx">  location ~ /.well-known {
<strong>    allow all;
</strong>  }
</code></pre>

### 手动续期方法 <a href="#manual-renewal-methods" id="manual-renewal-methods"></a>

```shell
# 定位到 /usr/local/acme.sh/ 目录
cd /usr/local/acme.sh/

# 手动续期 vault.yourdomain.com 的 Let’s Encrypt 证书
acme.sh --renew -d vault.yourdomain.com
```

如果由于某些原因无法手动续期，则可以通过 lnmp 命令删除虚拟主机然后重新添加虚拟主机的方式重新获取证书（此操作不会丢失 Vaultwarden 的数据，并且不需要对 Vaultwarden 做任何操作）：

1、备份 `vault.yourdomain.com` 虚拟主机的配置文件：`/usr/local/nginx/conf/vhost/vault.yourdomain.com.conf`

2、删除并重新创建 `vault.yourdomain.com` 虚拟主机：

```shell
# 删除虚拟主机
lnmp vhost del # 根据提示输入 vault.yourdomain.com 以删除此虚拟主机

# 删除网站文件
chattr -i /home/wwwroot/vault.yourdomain.com/.user.ini # 需要先执行此命令才能删除 .user.ini 文件
rm -rf /home/wwwroot/vault.yourdomain.com/ # 执行删除操作

# 新建虚拟主机
lnmp vhost add
# 根据提示输入使用的域名（这里为 vault.yourdomain.com）
# 选择使用 Let's Encrypt
# 其他如 Rewrite rule、PHP Pathinfo、access log、databse、ftp 等全部选 no
```

3、恢复 `vault.yourdomain.com` 虚拟主机的配置文件：`/usr/local/nginx/conf/vhost/vault.yourdomain.com.conf`

4、重启 nginx 使配置生效：

```shell
lnmp nginx restart

# 或者
/etc/init.d/nginx restart
```

## 在网页密码库后台进入 YubiKey OTP 安全钥匙的两步登录配置时出错 <a href="#two-step-login-for-yubikey-otp-error" id="two-step-login-for-yubikey-otp-error"></a>

### 错误内容 1 <a href="#error-1" id="error-1"></a>

> 发生错误。 `YUBICO_CLIENT_ID` or `YUBICO_SECRET_KEY` environment variable is not set. Yubikey OTP Disabled

原因为未设置配置文件 `config.json` 中 Yubico 的 `Client ID` 和 `Secret key` 环境变量的值。通过 [Yubico API key signup](https://upgrade.yubico.com/getapikey/) 页面注册您的 Yubico 的 `Client ID` 和 `Secret key`，然后将其通过管理页面或直接配置到 `config.json` 中即可。

### 错误内容 2 <a href="#error-2" id="error-2"></a>

> 发生错误。 Yubico support is disabled

原因为未启用 YubiKey，在管理员门户中启用即可。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://host.ppgg.in/vaultwarden/troubleshoot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
