Files
vue-driven-cloud-storage/fix_install_sh.sh
喻勇祥 225c3a5ded 🔧 更新install.sh - 添加Nginx Cookie传递配置
## 修改说明
install.sh生成的Nginx配置中缺少Cookie传递设置,
导致验证码session无法正常工作。

## 修改内容

### install.sh
在3处 `location /api` 配置中添加Cookie传递:

```nginx
# Cookie传递配置(验证码session需要)
proxy_set_header Cookie $http_cookie;
proxy_pass_header Set-Cookie;
```

修改位置:
- 行2383: HTTP配置(configure_nginx_http_first)
- 行2665: HTTPS配置(configure_nginx_final)
- 行2802: 虚拟主机配置

### 新增文件

1. **fix_install_sh.sh**
   - 自动化修改脚本
   - 备份原文件后自动添加Cookie配置
   - 可重复运行(检测已修改则跳过)

2. **INSTALL_SH_UPDATE.md**
   - 详细的修改说明文档
   - 手动修改方法
   - 验证和应用指南

## 使用方法

### 新部署
直接运行修改后的install.sh即可

### 自动修改
```bash
./fix_install_sh.sh
```

### 已部署服务
需要手动更新Nginx配置:
```bash
vim /etc/nginx/conf.d/玩玩云.conf
# 在 location /api 块中添加Cookie配置
nginx -t
nginx -s reload
```

## 配套修复
此修改配合以下提交才能完整工作:
- 后端session配置 (7ce9d95)
- 前端axios配置 (83773ef)
- nginx/nginx.conf (5f3fd38)
- install.sh (本提交)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 16:54:26 +00:00

83 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
#!/bin/bash
# 自动修改install.sh添加Cookie配置的脚本
set -e
echo "========================================="
echo "install.sh Cookie配置自动修改脚本"
echo "========================================="
echo ""
# 检查文件是否存在
if [[ ! -f "install.sh" ]]; then
echo "❌ 错误: install.sh文件不存在"
exit 1
fi
# 备份
echo "📦 备份install.sh..."
cp install.sh install.sh.backup.$(date +%Y%m%d%H%M%S)
echo "✅ 备份完成"
echo ""
# 检查是否已经修改过
if grep -q "Cookie传递配置" install.sh; then
echo " 检测到install.sh已经包含Cookie配置"
echo " 跳过修改"
exit 0
fi
echo "🔧 开始修改install.sh..."
echo ""
# 使用perl进行多行匹配和替换
perl -i -pe '
BEGIN {
$cookie_config = "\n" .
" # Cookie传递配置验证码session需要\n" .
" proxy_set_header Cookie \$http_cookie;\n" .
" proxy_pass_header Set-Cookie;";
}
# 在 location /api 块中的 X-Forwarded-Proto 后添加Cookie配置
if (/proxy_set_header X-Forwarded-Proto \\\$scheme;/ && $in_api_block) {
$_ .= $cookie_config . "\n";
$added_count++;
}
$in_api_block = 1 if /location \/api/;
$in_api_block = 0 if /^\s*\}/;
' install.sh
# 验证修改结果
count=$(grep -c "Cookie传递配置" install.sh || echo "0")
echo "========================================="
echo "修改完成"
echo "========================================="
echo ""
echo "📊 修改统计:"
echo " - 添加Cookie配置: $count"
echo ""
if [[ "$count" -eq 3 ]]; then
echo "✅ 成功修改了3处location /api配置"
echo ""
echo "修改位置:"
grep -n "Cookie传递配置" install.sh | sed 's/^/ 行 /'
echo ""
echo "📝 建议:"
echo " 1. 检查修改是否正确: diff install.sh.backup.* install.sh"
echo " 2. 提交到Git: git add install.sh && git commit -m '添加Cookie配置'"
echo " 3. 已部署的服务需要手动更新Nginx配置"
elif [[ "$count" -gt 0 ]]; then
echo "⚠️ 警告: 只修改了 $count预期应该是3处"
echo " 请手动检查install.sh文件"
else
echo "❌ 错误: 修改失败没有添加任何Cookie配置"
echo " 请查看 INSTALL_SH_UPDATE.md 手动修改"
fi
echo ""