332 lines
7.2 KiB
Markdown
332 lines
7.2 KiB
Markdown
|
|
# 远程服务器配置操作指南
|
|||
|
|
|
|||
|
|
## 方法一:使用宝塔面板(推荐)
|
|||
|
|
|
|||
|
|
### 1. 编辑配置文件
|
|||
|
|
|
|||
|
|
在宝塔面板中:
|
|||
|
|
1. 点击左侧菜单 **文件**
|
|||
|
|
2. 导航到 `/www/wwwroot/px.ddn-ai.cloud/jar/`
|
|||
|
|
3. 找到 `application.yml` 文件
|
|||
|
|
4. 点击 **编辑**
|
|||
|
|
|
|||
|
|
### 2. 粘贴配置内容
|
|||
|
|
|
|||
|
|
将以下内容完整复制并粘贴到 `application.yml` 文件中:
|
|||
|
|
|
|||
|
|
```yaml
|
|||
|
|
server:
|
|||
|
|
port: 8089
|
|||
|
|
servlet:
|
|||
|
|
context-path: /
|
|||
|
|
tomcat:
|
|||
|
|
uri-encoding: UTF-8
|
|||
|
|
|
|||
|
|
spring:
|
|||
|
|
application:
|
|||
|
|
name: peidu-backend
|
|||
|
|
profiles:
|
|||
|
|
active: prod
|
|||
|
|
mvc:
|
|||
|
|
pathmatch:
|
|||
|
|
matching-strategy: ant_path_matcher
|
|||
|
|
servlet:
|
|||
|
|
multipart:
|
|||
|
|
max-file-size: 10MB
|
|||
|
|
max-request-size: 10MB
|
|||
|
|
jackson:
|
|||
|
|
date-format: yyyy-MM-dd HH:mm:ss
|
|||
|
|
time-zone: GMT+8
|
|||
|
|
http:
|
|||
|
|
encoding:
|
|||
|
|
charset: UTF-8
|
|||
|
|
enabled: true
|
|||
|
|
force: true
|
|||
|
|
datasource:
|
|||
|
|
url: ${SPRING_DATASOURCE_URL}
|
|||
|
|
username: ${DB_USERNAME}
|
|||
|
|
password: ${DB_PASSWORD}
|
|||
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|||
|
|
hikari:
|
|||
|
|
minimum-idle: 5
|
|||
|
|
maximum-pool-size: 20
|
|||
|
|
connection-timeout: 30000
|
|||
|
|
idle-timeout: 600000
|
|||
|
|
max-lifetime: 1800000
|
|||
|
|
|
|||
|
|
mybatis-plus:
|
|||
|
|
mapper-locations: classpath*:/mapper/**/*.xml
|
|||
|
|
type-aliases-package: com.peidu.entity
|
|||
|
|
configuration:
|
|||
|
|
map-underscore-to-camel-case: true
|
|||
|
|
cache-enabled: false
|
|||
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|||
|
|
global-config:
|
|||
|
|
db-config:
|
|||
|
|
id-type: auto
|
|||
|
|
logic-delete-field: deleted
|
|||
|
|
logic-delete-value: 1
|
|||
|
|
logic-not-delete-value: 0
|
|||
|
|
|
|||
|
|
logging:
|
|||
|
|
level:
|
|||
|
|
com.peidu: info
|
|||
|
|
root: info
|
|||
|
|
pattern:
|
|||
|
|
console: '%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{50} - %msg%n'
|
|||
|
|
file:
|
|||
|
|
name: /www/wwwroot/px.ddn-ai.cloud/jar/logs/app.log
|
|||
|
|
|
|||
|
|
# ========================================
|
|||
|
|
# 文件上传配置 (关键配置)
|
|||
|
|
# ========================================
|
|||
|
|
file:
|
|||
|
|
upload:
|
|||
|
|
mode: local
|
|||
|
|
local-path: /www/wwwroot/px.ddn-ai.cloud/Image/
|
|||
|
|
url-prefix: https://px.ddn-ai.cloud/uploads/
|
|||
|
|
allowed-types: jpg,jpeg,png,gif,bmp,webp,pdf,doc,docx,xls,xlsx
|
|||
|
|
max-size: 10
|
|||
|
|
|
|||
|
|
jwt:
|
|||
|
|
secret: ${JWT_SECRET}
|
|||
|
|
expiration: 604800
|
|||
|
|
|
|||
|
|
wx:
|
|||
|
|
appid: ${WX_APPID}
|
|||
|
|
secret: ${WX_SECRET}
|
|||
|
|
|
|||
|
|
wechat:
|
|||
|
|
pay:
|
|||
|
|
appid: ${WX_PAY_APPID}
|
|||
|
|
mchid: ${WX_PAY_MCHID}
|
|||
|
|
key: ${WX_PAY_KEY}
|
|||
|
|
cert-path: classpath:cert/apiclient_cert.p12
|
|||
|
|
notify-url: https://px.ddn-ai.cloud/api/payment/notify/wechat
|
|||
|
|
|
|||
|
|
sms:
|
|||
|
|
skip-send: false
|
|||
|
|
aliyun:
|
|||
|
|
access-key-id: ${ALIYUN_SMS_ACCESS_KEY}
|
|||
|
|
access-key-secret: ${ALIYUN_SMS_ACCESS_SECRET}
|
|||
|
|
sign-name: ${SMS_SIGN_NAME}
|
|||
|
|
template-code: ${SMS_TEMPLATE_VERIFY_CODE}
|
|||
|
|
region: cn-hangzhou
|
|||
|
|
|
|||
|
|
aliyun:
|
|||
|
|
oss:
|
|||
|
|
endpoint: ${ALIYUN_OSS_ENDPOINT:}
|
|||
|
|
access-key-id: ${ALIYUN_OSS_ACCESS_KEY:}
|
|||
|
|
access-key-secret: ${ALIYUN_OSS_ACCESS_SECRET:}
|
|||
|
|
bucket-name: ${ALIYUN_OSS_BUCKET:}
|
|||
|
|
domain: ${ALIYUN_OSS_DOMAIN:}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3. 保存文件
|
|||
|
|
|
|||
|
|
点击 **保存** 按钮
|
|||
|
|
|
|||
|
|
### 4. 重启服务
|
|||
|
|
|
|||
|
|
在宝塔面板中:
|
|||
|
|
1. 找到 `start.sh` 文件
|
|||
|
|
2. 点击 **终端** 按钮
|
|||
|
|
3. 执行以下命令:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd /www/wwwroot/px.ddn-ai.cloud/jar
|
|||
|
|
bash start.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
或者直接在宝塔终端中执行:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 停止旧服务
|
|||
|
|
ps aux | grep peidu-backend | grep -v grep | awk '{print $2}' | xargs kill -9
|
|||
|
|
|
|||
|
|
# 启动新服务
|
|||
|
|
cd /www/wwwroot/px.ddn-ai.cloud/jar
|
|||
|
|
bash start.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 5. 查看日志
|
|||
|
|
|
|||
|
|
在宝塔面板中:
|
|||
|
|
1. 导航到 `/www/wwwroot/px.ddn-ai.cloud/jar/logs/`
|
|||
|
|
2. 打开 `app.log` 文件
|
|||
|
|
3. 查找以下内容,确认配置生效:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
========================================
|
|||
|
|
📁 文件上传配置初始化
|
|||
|
|
上传模式: local
|
|||
|
|
本地保存路径: /www/wwwroot/px.ddn-ai.cloud/Image/
|
|||
|
|
✅ 本地保存模式
|
|||
|
|
访问URL前缀: https://px.ddn-ai.cloud/uploads/
|
|||
|
|
========================================
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 方法二:使用SSH命令行
|
|||
|
|
|
|||
|
|
### 1. 登录服务器
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
ssh root@px.ddn-ai.cloud
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 编辑配置文件
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd /www/wwwroot/px.ddn-ai.cloud/jar
|
|||
|
|
vi application.yml
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
按 `i` 进入编辑模式,粘贴上面的配置内容,然后:
|
|||
|
|
- 按 `Esc` 退出编辑模式
|
|||
|
|
- 输入 `:wq` 保存并退出
|
|||
|
|
|
|||
|
|
### 3. 重启服务
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
bash start.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4. 查看日志
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
tail -f logs/app.log
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 验证配置
|
|||
|
|
|
|||
|
|
### 1. 测试上传接口
|
|||
|
|
|
|||
|
|
在本地电脑上执行:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
curl -X POST https://px.ddn-ai.cloud/api/file/upload/direct \
|
|||
|
|
-F "file=@test.jpg"
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
应该返回:
|
|||
|
|
|
|||
|
|
```json
|
|||
|
|
{
|
|||
|
|
"code": 200,
|
|||
|
|
"message": "上传成功",
|
|||
|
|
"data": {
|
|||
|
|
"fileName": "20260126_xxx.jpg",
|
|||
|
|
"fileUrl": "https://px.ddn-ai.cloud/uploads/20260126_xxx.jpg",
|
|||
|
|
"fileSize": "12345",
|
|||
|
|
"fileType": "jpg"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**关键检查:** `fileUrl` 必须是 `https://px.ddn-ai.cloud/uploads/...`
|
|||
|
|
|
|||
|
|
### 2. 测试本地管理后台上传
|
|||
|
|
|
|||
|
|
1. 打开本地管理后台
|
|||
|
|
2. 进入轮播图管理
|
|||
|
|
3. 上传一张图片
|
|||
|
|
4. 检查返回的URL是否为 `https://px.ddn-ai.cloud/uploads/...`
|
|||
|
|
5. 检查图片是否能正常显示
|
|||
|
|
|
|||
|
|
### 3. 直接访问图片
|
|||
|
|
|
|||
|
|
在浏览器中访问:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
https://px.ddn-ai.cloud/uploads/20260126_xxx.jpg
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
应该能正常显示图片。
|
|||
|
|
|
|||
|
|
## 关键配置说明
|
|||
|
|
|
|||
|
|
### 最重要的配置项
|
|||
|
|
|
|||
|
|
```yaml
|
|||
|
|
file:
|
|||
|
|
upload:
|
|||
|
|
mode: local # 远程服务器使用local模式
|
|||
|
|
local-path: /www/wwwroot/px.ddn-ai.cloud/Image/ # 文件保存路径
|
|||
|
|
url-prefix: https://px.ddn-ai.cloud/uploads/ # ⚠️ 必须是远程地址!
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 为什么url-prefix必须是远程地址?
|
|||
|
|
|
|||
|
|
因为:
|
|||
|
|
1. 本地开发环境会调用远程服务器的 `/api/file/upload/direct` 接口
|
|||
|
|
2. 远程服务器保存文件后,返回 `fileUrl`
|
|||
|
|
3. 这个 `fileUrl` 会被本地后端转发给前端
|
|||
|
|
4. 前端使用这个 `fileUrl` 来显示图片
|
|||
|
|
5. 如果 `url-prefix` 是 `localhost`,前端就无法加载图片
|
|||
|
|
|
|||
|
|
### 配置流程图
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
本地前端 → 本地后端(remote模式) → 远程服务器(local模式)
|
|||
|
|
↓
|
|||
|
|
保存到 /www/.../Image/
|
|||
|
|
↓
|
|||
|
|
返回 https://px.ddn-ai.cloud/uploads/xxx.jpg
|
|||
|
|
↓
|
|||
|
|
本地后端转发给前端
|
|||
|
|
↓
|
|||
|
|
前端显示图片 ✅
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 常见问题
|
|||
|
|
|
|||
|
|
### Q1: 配置后还是返回localhost地址?
|
|||
|
|
|
|||
|
|
**原因:** 服务没有重启,还在使用旧配置
|
|||
|
|
|
|||
|
|
**解决:**
|
|||
|
|
```bash
|
|||
|
|
# 强制停止
|
|||
|
|
ps aux | grep peidu-backend | grep -v grep | awk '{print $2}' | xargs kill -9
|
|||
|
|
|
|||
|
|
# 重新启动
|
|||
|
|
cd /www/wwwroot/px.ddn-ai.cloud/jar
|
|||
|
|
bash start.sh
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q2: 图片上传成功但无法访问?
|
|||
|
|
|
|||
|
|
**原因:** Nginx配置问题或文件权限问题
|
|||
|
|
|
|||
|
|
**解决:**
|
|||
|
|
```bash
|
|||
|
|
# 检查文件是否存在
|
|||
|
|
ls -la /www/wwwroot/px.ddn-ai.cloud/Image/
|
|||
|
|
|
|||
|
|
# 修改权限
|
|||
|
|
chmod 755 /www/wwwroot/px.ddn-ai.cloud/Image/
|
|||
|
|
chmod 644 /www/wwwroot/px.ddn-ai.cloud/Image/*
|
|||
|
|
|
|||
|
|
# 检查Nginx配置
|
|||
|
|
cat /www/server/panel/vhost/nginx/px.ddn-ai.cloud.conf | grep uploads
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q3: 如何查看当前配置是否生效?
|
|||
|
|
|
|||
|
|
**方法1:** 查看启动日志
|
|||
|
|
```bash
|
|||
|
|
tail -100 /www/wwwroot/px.ddn-ai.cloud/jar/logs/app.log | grep "文件上传配置"
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**方法2:** 测试上传接口
|
|||
|
|
```bash
|
|||
|
|
curl -X POST https://px.ddn-ai.cloud/api/file/upload/direct \
|
|||
|
|
-F "file=@test.jpg" | jq .data.fileUrl
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
应该输出:`"https://px.ddn-ai.cloud/uploads/xxx.jpg"`
|
|||
|
|
|
|||
|
|
## 日期
|
|||
|
|
|
|||
|
|
2026-01-26
|