Files
AIGC/demo/HOSTS_SETUP.md
AIGC Developer 26d10a3322 配置自定义域名开发环境
- 修改hosts文件配置,添加测试域名映射
- 前端API地址改为 api.yourdomain.com:8080
- 后端服务绑定到 api.yourdomain.com:8080
- 前端开发服务器使用 test.yourdomain.com:5173
- 添加自动配置脚本和启动脚本
- 提供完整的域名配置指南和故障排除说明
- 支持更真实的开发环境模拟
2025-10-23 10:40:57 +08:00

92 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Hosts文件配置指南
## 手动配置步骤
### 1. 以管理员身份打开记事本
1.`Win + R` 打开运行对话框
2. 输入 `notepad` 并按 `Ctrl + Shift + Enter`(以管理员身份运行)
3. 点击"是"确认
### 2. 打开hosts文件
1. 在记事本中,点击"文件" -> "打开"
2. 导航到 `C:\Windows\System32\drivers\etc\`
3. 将文件类型改为"所有文件"
4. 选择 `hosts` 文件并打开
### 3. 添加域名映射
在hosts文件末尾添加以下内容
```
# AIGC Demo 测试域名映射
127.0.0.1 test.yourdomain.com
127.0.0.1 api.yourdomain.com
127.0.0.1 local.yourdomain.com
```
### 4. 保存文件
1.`Ctrl + S` 保存
2. 关闭记事本
## 自动配置(推荐)
### 使用PowerShell脚本
1. 右键点击 `update-hosts.ps1`
2. 选择"使用PowerShell运行"
3. 如果提示执行策略,运行:
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
## 验证配置
### 测试域名解析
```cmd
ping test.yourdomain.com
ping api.yourdomain.com
```
应该显示 `127.0.0.1` 的响应。
## 配置完成后
### 前端配置
修改前端代码中的API地址
```javascript
// 在 src/api/request.js 中
const API_BASE_URL = 'http://api.yourdomain.com:8080/api';
```
### 后端配置
修改后端服务绑定地址:
```java
// 在 application.properties 中
server.address=api.yourdomain.com
server.port=8080
```
## 域名说明
- `test.yourdomain.com` - 前端测试域名
- `api.yourdomain.com` - 后端API域名
- `local.yourdomain.com` - 本地开发域名
## 故障排除
### 如果域名不生效
1. 清除DNS缓存
```cmd
ipconfig /flushdns
```
2. 重启浏览器
3. 检查hosts文件格式
- 确保没有多余的空格
- 确保使用Tab或空格分隔IP和域名
- 确保没有#注释掉映射
### 如果无法保存hosts文件
1. 确保以管理员身份运行记事本
2. 检查文件是否被其他程序占用
3. 尝试复制到桌面修改后再覆盖原文件