setup_proxy.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. echo "=== 代理程序安装脚本 ==="
  3. # 检测系统类型
  4. if [ -f /etc/debian_version ]; then
  5. echo "检测到 Debian/Ubuntu 系统"
  6. PKG_MANAGER="apt-get"
  7. elif [ -f /etc/redhat-release ]; then
  8. echo "检测到 CentOS/RHEL 系统"
  9. PKG_MANAGER="yum"
  10. else
  11. echo "未知系统类型,请手动安装"
  12. exit 1
  13. fi
  14. # 安装依赖
  15. echo "安装依赖包..."
  16. sudo $PKG_MANAGER update
  17. sudo $PKG_MANAGER install -y wget curl unzip
  18. # 下载 goproxy
  19. echo "下载 goproxy..."
  20. cd /tmp
  21. wget https://github.com/snail007/goproxy/releases/download/v13.3/proxy-linux-amd64.tar.gz
  22. tar -xzf proxy-linux-amd64.tar.gz
  23. sudo mv proxy /usr/local/bin/
  24. sudo chmod +x /usr/local/bin/proxy
  25. # 创建配置文件
  26. echo "创建配置文件..."
  27. sudo mkdir -p /etc/goproxy
  28. sudo tee /etc/goproxy/config.json > /dev/null <<EOF
  29. {
  30. "proxy": {
  31. "http": {
  32. "port": 80,
  33. "target": "https://andys-dandy-site-4c8fd6.webflow.io",
  34. "replace": {
  35. "andys-dandy-site-4c8fd6.webflow.io": "pog.cxhy.cn",
  36. "https://andys-dandy-site-4c8fd6.webflow.io": "https://pog.cxhy.cn"
  37. }
  38. }
  39. }
  40. }
  41. EOF
  42. # 创建systemd服务
  43. echo "创建系统服务..."
  44. sudo tee /etc/systemd/system/goproxy.service > /dev/null <<EOF
  45. [Unit]
  46. Description=GoProxy Service
  47. After=network.target
  48. [Service]
  49. Type=simple
  50. User=root
  51. ExecStart=/usr/local/bin/proxy http -t tcp -p "0.0.0.0:80" --forever
  52. Restart=always
  53. RestartSec=5
  54. [Install]
  55. WantedBy=multi-user.target
  56. EOF
  57. # 启动服务
  58. echo "启动服务..."
  59. sudo systemctl daemon-reload
  60. sudo systemctl enable goproxy
  61. sudo systemctl start goproxy
  62. # 检查状态
  63. echo "检查服务状态..."
  64. sudo systemctl status goproxy
  65. echo "=== 安装完成 ==="
  66. echo "代理服务已启动在端口 80"
  67. echo "目标网站: andys-dandy-site-4c8fd6.webflow.io"
  68. echo "显示域名: pog.cxhy.cn"
  69. echo ""
  70. echo "管理命令:"
  71. echo "启动: sudo systemctl start goproxy"
  72. echo "停止: sudo systemctl stop goproxy"
  73. echo "重启: sudo systemctl restart goproxy"
  74. echo "状态: sudo systemctl status goproxy"
  75. echo "日志: sudo journalctl -u goproxy -f"