haoel / haoel.github.io

12.73k stars 2.03k forks source link

为什么按照步骤设置完之后,服务都是通的,代理也生效了,但是在 go 服务中运行会几次成功才会成功一次 #283

Open ymichaelson opened 11 months ago

ymichaelson commented 11 months ago

gost 配置

#!/bin/bash

# 下面的四个参数需要改成你的
DOMAIN="xxx.com"
USER="USER"
PASS="PASS"
PORT=443
AUTH=$(echo -n ${USER}:${PASS} | base64)

BIND_IP=0.0.0.0
CERT_DIR=/etc/letsencrypt
CERT=${CERT_DIR}/live/${DOMAIN}/fullchain.pem
KEY=${CERT_DIR}/live/${DOMAIN}/privkey.pem
sudo docker run -d --name gost \
    -v ${CERT_DIR}:${CERT_DIR}:ro \
    --net=host ginuerzh/gost \
    -L "http2://${BIND_IP}:${PORT}?auth=${AUTH}&cert=${CERT}&key=${KEY}&probe_resist=code:404&knock=www.google.com"

go http proxy

package main

import (
    "crypto/tls"
    "encoding/base64"
    "fmt"
    "io"
    "log"
    "net/http"
    "net/url"
)

func main() {
    // 代理服务器的信息
    proxyURLStr := "https://xxx.com:443"
    proxyUsername := "username"
    proxyPassword := "password"

    // 编码代理认证信息
    auth := proxyUsername + ":" + proxyPassword
    basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))

    // 解析代理服务器 URL
    proxyURL, err := url.Parse(proxyURLStr)
    if err != nil {
        log.Fatal(err)
    }

    // 自定义 Transport
    transport := &http.Transport{
        Proxy: http.ProxyURL(proxyURL),
        ProxyConnectHeader: http.Header{
            "Proxy-Authorization": []string{basicAuth},
        },
        TLSClientConfig: &tls.Config{
            InsecureSkipVerify: true,
        },
    }

    // 创建一个新的 HTTP 客户端
    client := &http.Client{
        Transport: transport,
    }

    // 发送 GET 请求
    response, err := client.Get("https://chat.openai.com")
    if err != nil {
        log.Fatal(err)
    }
    defer response.Body.Close()

    // 读取响应内容
    body, err := io.ReadAll(response.Body)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(string(body))
}

运行日志:

[ec2-user@ip-172-31-1-4 ~]$ ./proxy
2023/12/01 14:30:24 Get "https://chat.openai.com": Bad Request
[ec2-user@ip-172-31-1-4 ~]$ ./proxy
2023/12/01 14:30:26 Get "https://chat.openai.com": Bad Request
[ec2-user@ip-172-31-1-4 ~]$ ./proxy
2023/12/01 14:30:28 Get "https://chat.openai.com": Bad Request
[ec2-user@ip-172-31-1-4 ~]$ ./proxy
<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="robots" content="noindex,nofollow"><meta name="viewport" content="width=device-width,initial-scale=1"><link href="/cdn-cgi/styles/challenges.css" rel="stylesheet"><meta http-equiv="refresh" content="375"></head><body class="no-js"><div class="main-wrapper" role="main"><div class="main-content"><noscript><div id="challenge-error-title"><div class="h2"><span class="icon-wrapper"><div class="heading-icon warning-icon"></div></span><span id="challenge-error-text">Enable JavaScript and cookies to continue</span></div></div></noscript></div></div><script>(function(){window._cf_chl_opt={cvId: '2',cZone: "chat.openai.com",cType: 'managed',cNounce: '75110',cRay: '82e94825e8bcfb50',cHash: '43a1ac5efde1f42',cUPMDTk: "\/?__cf_chl_tk=tFYZBe7zmto5rV4FS8hYAvYNFHbCgm.Z9.NaHr1YHqI-1701412230-0-gaNycGzNCZA",cFPWv: 'g',cTTimeMs: '1000',cMTimeMs: '375000',cTplV: 5,cTplB: 'cf',cK: "visitor-time",fa: "\/?__cf_chl_f_tk=tFYZBe7zmto5rV4FS8hYAvYNFHbCgm.Z9.NaHr1YHqI-1701412230-0-gaNycGzNCZA",md: "QXmLELLV8CxezSqJP_9oJIuSKyPQd49YoYVjrQwUEjs-1701412230-0-Afyq9Rz98FOa0ia8fcXojetCW5O7nIS_Ich11tVxgwV7u7UgwlFc7DH-PJ74xm_gCM8hAcIu626S33DY_aG16QlRu2rXpy3RL3xoXtmtSBTc2fpGKzeRerYM1-q303jZEACzXQ189DvTpp2vvI8cPzMXwz9ZkVwCVIzZQfxrxy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GGlVCZaNUJIHhxzxFNzSPNnVe6rJjiQw728=',}};var cpo = document.createElement('script');cpo.src = '/cdn-cgi/challenge-platform/h/g/orchestrate/chl_page/v1?ray=82e94825e8bcfb50';window._cf_chl_opt.cOgUHash = location.hash === '' && location.href.indexOf('#') !== -1 ? '#' : location.hash;window._cf_chl_opt.cOgUQuery = location.search === '' && location.href.slice(0, location.href.length - window._cf_chl_opt.cOgUHash.length).indexOf('?') !== -1 ? '?' : location.search;if (window.history && window.history.replaceState) {var ogU = location.pathname + window._cf_chl_opt.cOgUQuery + window._cf_chl_opt.cOgUHash;history.replaceState(null, null, "\/?__cf_chl_rt_tk=tFYZBe7zmto5rV4FS8hYAvYNFHbCgm.Z9.NaHr1YHqI-1701412230-0-gaNycGzNCZA" + window._cf_chl_opt.cOgUHash);cpo.onload = function() {history.replaceState(null, null, ogU);}}document.getElementsByTagName('head')[0].appendChild(cpo);}());</script></body></html>
[ec2-user@ip-172-31-1-4 ~]$

gost server 日志:

2023/12/01 06:22:26 http2.go:429: [route] 71.132.56.236:34448 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:22:26 http2.go:466: [http2] 71.132.56.236:34448 <-> chat.openai.com:443 : downgrade to HTTP/1.1
2023/12/01 06:22:27 http2.go:468: [http2] 71.132.56.236:34448 >-< chat.openai.com:443
2023/12/01 06:24:34 http2.go:360: [http2] endverse@71.132.56.236:57924 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:24:34 http2.go:429: [route] 71.132.56.236:57924 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:24:34 http2.go:466: [http2] 71.132.56.236:57924 <-> chat.openai.com:443 : downgrade to HTTP/1.1
2023/12/01 06:24:34 http2.go:468: [http2] 71.132.56.236:57924 >-< chat.openai.com:443
2023/12/01 06:24:41 http2.go:360: [http2] endverse@71.132.56.236:54300 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:24:41 http2.go:429: [route] 71.132.56.236:54300 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:24:41 http2.go:466: [http2] 71.132.56.236:54300 <-> chat.openai.com:443 : downgrade to HTTP/1.1
2023/12/01 06:24:41 http2.go:468: [http2] 71.132.56.236:54300 >-< chat.openai.com:443

2023/12/01 06:30:29 http2.go:360: [http2] endverse@71.132.56.236:36494 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:30:29 http2.go:429: [route] 71.132.56.236:36494 -> http2://0.0.0.0:443 -> chat.openai.com:443
2023/12/01 06:30:29 http2.go:466: [http2] 71.132.56.236:36494 <-> chat.openai.com:443 : downgrade to HTTP/1.1
2023/12/01 06:30:30 http2.go:468: [http2] 71.132.56.236:36494 >-< chat.openai.com:443

大概平均请求三次,这个请求才会转发到 gost server,这是为什么,是什么设置导致的吗?

novohool commented 8 months ago

还是烧点纸吧