fix: 修复SSH隧道端口转发和Cookie配置问题
This commit is contained in:
@@ -52,7 +52,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const response = NextResponse.json({ success: true, username: user.username });
|
const response = NextResponse.json({ success: true, username: user.username });
|
||||||
response.cookies.set('auth_token', newToken, {
|
response.cookies.set('auth_token', newToken, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: process.env.NODE_ENV === 'production',
|
secure: false,
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
path: '/'
|
path: '/'
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const response = NextResponse.json({ success: true, username });
|
const response = NextResponse.json({ success: true, username });
|
||||||
response.cookies.set('auth_token', token, {
|
response.cookies.set('auth_token', token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: process.env.NODE_ENV === 'production',
|
secure: false,
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
path: '/'
|
path: '/'
|
||||||
|
|||||||
72
port_forwarding.sh
Executable file
72
port_forwarding.sh
Executable file
@@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
REMOTE_HOST="47.120.74.73"
|
||||||
|
REMOTE_PORT="30000"
|
||||||
|
LOCAL_PORT="3000"
|
||||||
|
SSH_PORT="22"
|
||||||
|
SSH_PASSWORD="MyPassword2+"
|
||||||
|
PID_FILE="/tmp/ssh_tunnel.pid"
|
||||||
|
LOG_FILE="/tmp/ssh_tunnel.log"
|
||||||
|
|
||||||
|
start_tunnel() {
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
OLD_PID=$(cat "$PID_FILE")
|
||||||
|
if kill -0 "$OLD_PID" 2>/dev/null; then
|
||||||
|
echo "SSH隧道已在运行 (PID: $OLD_PID)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "正在启动SSH反向隧道..."
|
||||||
|
sshpass -p "$SSH_PASSWORD" ssh -N -g -R "0.0.0.0:$REMOTE_PORT":localhost:"$LOCAL_PORT" -p "$SSH_PORT" -o "ServerAliveInterval=60" -o "ServerAliveCountMax=3" root@"$REMOTE_HOST" > "$LOG_FILE" 2>&1 &
|
||||||
|
SSH_PID=$!
|
||||||
|
echo "$SSH_PID" > "$PID_FILE"
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
if kill -0 "$SSH_PID" 2>/dev/null; then
|
||||||
|
echo "SSH隧道已启动 (本地3000 -> 远程$REMOTE_PORT)"
|
||||||
|
else
|
||||||
|
echo "启动失败,查看日志: cat $LOG_FILE"
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_tunnel() {
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
PID=$(cat "$PID_FILE")
|
||||||
|
if kill -0 "$PID" 2>/dev/null; then
|
||||||
|
kill "$PID"
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
echo "SSH隧道已停止"
|
||||||
|
else
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
echo "隧道未运行"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "未找到PID文件,尝试直接终止"
|
||||||
|
pkill -f "ssh -N -R $REMOTE_PORT:localhost:$LOCAL_PORT"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
status_tunnel() {
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
PID=$(cat "$PID_FILE")
|
||||||
|
if kill -0 "$PID" 2>/dev/null; then
|
||||||
|
echo "SSH隧道正在运行 (PID: $PID)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "SSH隧道未运行"
|
||||||
|
echo "尝试检测进程..."
|
||||||
|
if pgrep -f "ssh -N -R $REMOTE_PORT" > /dev/null; then
|
||||||
|
echo "发现隧道进程,但无PID文件"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start) start_tunnel ;;
|
||||||
|
stop) stop_tunnel ;;
|
||||||
|
status) status_tunnel ;;
|
||||||
|
*) echo "Usage: $0 {start|stop|status}" ;;
|
||||||
|
esac
|
||||||
Reference in New Issue
Block a user