NakanoMiku39
Articles17
Tags31
Categories3

Categories

Archive

部署Blessing skin server中遇到的问题

部署Blessing skin server中遇到的问题

浅浅记录一下给社团安装Blessing skin server时踩的坑

1. 选择Apache还是Nginx还是Caddy

原本打算使用Nginx,但由于php的fastcgi在Nginx上配置麻烦,于是转而使用了Caddy

也不是麻烦,只是没有仔细阅读https://www.digitalocean.com/community/tutorials/php-fpm-nginx

2. 为什么访问页面403

检查目录权限问题

3. 为什么访问不到页面/为什么访问页面后直接下载了index.php

检查配置文件中(Caddyfile)是否有如下对php-fastcgi的配置
php_fastcgi unix//run/php/php8.1-fpm.sock

尤其注意是否与路径/etc/php/8.1/fpm/pool.d/www.conflisten = /run/php/php8.1-fpm.sock对应

4. 为什么setup时配置服务器后显示could not find driver

缺少了PDO拓展,检查是否安装了php-pgsql / php-mysql插件,然后重启php

5. 为什么配置了https就没法访问但配置了http就可以

社团有一个https透明代理,如果Caddyfile还是用https://就会导致问题,具体表现可能有502重定向次数过多,只需要用http://就行

如果使用Nginx的话应该就没有这个问题 – syh

6. caddy startsystemctl start caddy有什么区别

caddy start是将Caddy作为后台进程给运行,而systemctl start caddy是系统进程,如果当前会话中断,由caddy start启动的Caddy进程也会结束

7. 在配置Yggdrasil API插件后,启动器尝试认证是显示服务器响应解析失败

从启动器(HMCL)中导出日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex,nofollow">
<title>500 Internal Server Error - PMC</title>
<link href="/app/spectre.e885dd0.css" rel="stylesheet" crossorigin="anonymous">
</head>

<body class="bg-gray">
<div class="text-right m-2 p-2">
<a href="https://mc.lcpu.dev/api/yggdrasil/authserver/authenticate?lang=zh_CN"
class="mx-2 p-1 label label-secondary"
>中文 (简体)</a>
<a href="https://mc.lcpu.dev/api/yggdrasil/authserver/authenticate?lang=zh_TW"
class="mx-2 p-1 label label-secondary"
>中文 (正體)</a>
<a href="https://mc.lcpu.dev/api/yggdrasil/authserver/authenticate?lang=en"
class="mx-2 p-1 label label-secondary"
>English</a>
<a href="https://mc.lcpu.dev/api/yggdrasil/authserver/authenticate?lang=es_ES"
class="mx-2 p-1 label label-secondary"
>Español</a>
<a href="https://mc.lcpu.dev/api/yggdrasil/authserver/authenticate?lang=ru_RU"
class="mx-2 p-1 label label-secondary"
>Русский язык</a>
</div>

<div class="hero d-flex">
<div class="hero-body text-center">
<h1><a class="text-primary" href="https://mc.lcpu.dev">PMC</a></h1>
<div class="divider"></div>
<h3 style="margin-top: 15vh;">500 Internal Server Error</h3>
<p>
详细信息:Lcobucci\JWT\Signer\Key\InMemory::plainText(): Argument #1 ($contents) must be of type string, null given, called in /var/www/blessing-skin/plugins/yggdrasil-api/src/Controllers/AuthController.php on line 37
</p>
<div class="divider"></div>
</div>
</div>
</body>
</html>

可以看到直接定位到了问题位置,在/var/www/blessing-skin/plugins/yggdrasil-api/src/Controllers/AuthController.php,由于我对php和项目都不熟悉,所以接下来用ChatGPT-4o解决问题。

首先定位到代码:

1
JWT\Signer\Key\InMemory::plainText(config('jwt.secret', ''))

config('jwt.secret', '')试图从配置文件中获取jwt.secret配置项的值。而问题的根本原因是config('jwt.secret', '')返回了null,导致plainText()接收到不正确的参数,而这实际上是因为.env文件中没有JWT_SECRET项导致的(后来发现没有JWT_SECRET=xxxx),解决方法很明显,把这个项补上就行了。

config/jwt.php中有如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*                                                                                                               |
|-------------------------------------------------------------------------- |
| JWT Authentication Secret |
|-------------------------------------------------------------------------- |
| |
| Don't forget to set this in your .env file, as it will be used to sign |
| your tokens. A helper command is provided for this: |
| php artisan jwt:secret |
| |
| Note: This will be used for Symmetric algorithms only (HMAC), |
| since RSA and ECDSA use a private/public key combo (See below). |
| |
*/ |
'secret' => env('JWT_SECRET'),

只需输入注释中的指令php artisan jwt:secret就能生成JWT_SECRET,但在我的情况中,我并没有成功运行,而是得到了如下报错:
ERROR There are no commands defined in the "jwt" namespace.

这是可能是因为没有安装jwt-auth包,运行

1
composer require tymon/jwt-auth

如果像我一样还出现了依赖问题,可以运行

1
composer require tymon/jwt-auth -W

-W选项允许Composer同时升级、降级或删除当前锁定的依赖,确保可以安装兼容的版本,更新composer.lock文件中所有依赖,并安装兼容的tymon/jwt-authlcobucci/jwt版本,如果有需求的话也可以指定版本(例:4.0):composer require lcobucci/jwt:^4.0 tymon/jwt-auth

完成安装后继续重新设置jwt-auth,运行一下命令发布配置文件:

1
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

最后再生成JWT_SECRET

1
php artisan jwt:secret
Author:NakanoMiku39
Link:http://nakanomiku39.github.io/2024/09/09/%E9%83%A8%E7%BD%B2Blessing-skin-server%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可