V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
iCodex
V2EX  ›  问与答

试验了几个反向代理,发现都面临一个问题

  •  
  •   iCodex · 2016-10-28 17:35:35 +08:00 · 6677 次点击
    这是一个创建于 2946 天前的主题,其中的信息可能已经有所发展或是发生改变。

    试验环境

    主机: Mac 运行 Valte 跑 phpcms 程序,不加任何反代在本机或在内网内打开 phpcms.dev 进行任何操作都不会有问题的。

    内网三台机器,全部最小化安装 ubuntu 14.04 lts , apt 直接安装各软件

    • 内网 A 机器: nginx 反代
    • 内网 B 机器: varnish 反代
    • 内网 C 机器: squid 反代

    配置都是直接拿官方教科书一般的配置文件,添加进去的配置少得可怜,连缓存都不会有的,不影响测试。

    nginx 配置:

    server {
      listen 80 default fastopen=256 reuseport;
      server_name _;
      access_log /var/log/nginx/proxy-access.log combined;
      error_log /var/log/nginx/proxy-error.log;
    
      resolver 8.8.4.4 8.8.8.8 valid=300s;
      resolver_timeout 10s;
    
      location / {
        proxy_pass http://172.16.1.168;
        include proxy.inc;
      }
    }
    

    varnish 配置: https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl

    squid 配置只是在原有默认配置上加了cache_peer上游服务器,访问其他都是没问题,唯独这个 phpcms 的安装步骤。

    主要问题是在进行安装的第三步 post 数据时就一定过不去了,在 chrome 抓取到的错误信息如下:

    156585: URL_REQUEST
    http://phpcms.dev/install/install.php?
    Start Time: 2016-10-28 17:19:10.326
    
    t= 2381 [st=    0] +REQUEST_ALIVE  [dt=24547]
    t= 2381 [st=    0]    DELEGATE_INFO  [dt=13]
                          --> delegate_info = "NavigationResourceThrottle"
    t= 2394 [st=   13]   +URL_REQUEST_DELEGATE  [dt=2]
    t= 2394 [st=   13]      DELEGATE_INFO  [dt=2]
                            --> delegate_info = "扩展程序“ uBlock Origin ”"
    t= 2396 [st=   15]   -URL_REQUEST_DELEGATE
    t= 2396 [st=   15]   +URL_REQUEST_START_JOB  [dt=24518]
                          --> load_flags = 37122 (BYPASS_CACHE | MAIN_FRAME | MAYBE_USER_GESTURE | VERIFY_EV_CERT)
                          --> method = "POST"
                          --> priority = "HIGHEST"
                          --> upload_id = "1477638942369727"
                          --> url = "http://phpcms.dev/install/install.php?"
    t= 2396 [st=   15]      URL_REQUEST_DELEGATE  [dt=0]
    t= 2396 [st=   15]      HTTP_CACHE_GET_BACKEND  [dt=0]
    t= 2396 [st=   15]      HTTP_CACHE_DOOM_ENTRY  [dt=0]
                            --> net_error = -2 (ERR_FAILED)
    t= 2396 [st=   15]      HTTP_CACHE_CREATE_ENTRY  [dt=0]
    t= 2396 [st=   15]      HTTP_CACHE_ADD_TO_ENTRY  [dt=0]
    t= 2397 [st=   16]     +HTTP_STREAM_REQUEST  [dt=6]
    t= 2397 [st=   16]        HTTP_STREAM_REQUEST_STARTED_JOB
                              --> source_dependency = 156588 (HTTP_STREAM_JOB)
    t= 2403 [st=   22]        HTTP_STREAM_REQUEST_BOUND_TO_JOB
                              --> source_dependency = 156588 (HTTP_STREAM_JOB)
    t= 2403 [st=   22]     -HTTP_STREAM_REQUEST
    t= 2403 [st=   22]     +UPLOAD_DATA_STREAM_INIT  [dt=0]
    t= 2403 [st=   22]        UPLOAD_DATA_STREAM_INIT  [dt=0]
                              --> is_chunked = false
                              --> net_error = 0 (?)
                              --> total_size = 389
    t= 2403 [st=   22]     -UPLOAD_DATA_STREAM_INIT
                            --> is_chunked = false
                            --> net_error = 0 (?)
                            --> total_size = 389
    t= 2403 [st=   22]     +HTTP_TRANSACTION_SEND_REQUEST  [dt=1]
    t= 2403 [st=   22]        HTTP_TRANSACTION_SEND_REQUEST_HEADERS
                              --> POST /install/install.php? HTTP/1.1
                                  Host: phpcms.dev
                                  Connection: keep-alive
                                  Content-Length: 389
                                  Pragma: no-cache
                                  Cache-Control: no-cache
                                  Origin: http://phpcms.dev
                                  Upgrade-Insecure-Requests: 1
                                  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
                                  Content-Type: application/x-www-form-urlencoded
                                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
                                  DNT: 1
                                  Referer: http://phpcms.dev/install/install.php?step=3
                                  Accept-Encoding: gzip, deflate
                                  Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ja;q=0.2
    t= 2403 [st=   22]        HTTP_TRANSACTION_SEND_REQUEST_BODY
                              --> did_merge = false
                              --> is_chunked = false
                              --> length = 389
    t= 2403 [st=   22]       +UPLOAD_DATA_STREAM_READ  [dt=1]
                              --> current_position = 0
    t= 2403 [st=   22]          UPLOAD_DATA_STREAM_READ  [dt=1]
                                --> current_position = 0
    t= 2404 [st=   23]       -UPLOAD_DATA_STREAM_READ
    t= 2404 [st=   23]        UPLOAD_DATA_STREAM_READ  [dt=0]
                              --> current_position = 389
    t= 2404 [st=   23]     -HTTP_TRANSACTION_SEND_REQUEST
    t= 2404 [st=   23]     +HTTP_TRANSACTION_READ_HEADERS  [dt=24510]
    t= 2404 [st=   23]        HTTP_STREAM_PARSER_READ_HEADERS  [dt=24510]
                              --> net_error = -324 (ERR_EMPTY_RESPONSE)
    t=26914 [st=24533]     -HTTP_TRANSACTION_READ_HEADERS
                            --> net_error = -324 (ERR_EMPTY_RESPONSE)
    t=26914 [st=24533]   -URL_REQUEST_START_JOB
                          --> net_error = -324 (ERR_EMPTY_RESPONSE)
    t=26926 [st=24545]    URL_REQUEST_DELEGATE  [dt=1]
    t=26928 [st=24547] -REQUEST_ALIVE
                        --> net_error = -324 (ERR_EMPTY_RESPONSE)
    

    看到最后的 HTTP_TRANSACTION_READ_HEADERS ,耗时 24510 ,然后网页就返回无响应被重置了。

    第 1 条附言  ·  2016-10-28 18:25:59 +08:00
    在公网上放了个 phpcms ,然后用了腾讯云的 CDN 、百度云的 CDN 、还有 Keycdn ,
    腾讯云百度云都可以正常跳到后续的步骤, keycdn 过不去。

    是我漏掉哪个配置?
    第 2 条附言  ·  2016-10-29 02:36:14 +08:00

    之前附言不正确,腾讯云CDN 大部分节点的服务器都没法正常走完整个流程,遇到的问题和本地测试的情况是一致的。除了用 chrome 进行测试,可以用 curl 模拟提交,后端无法返回数据。

    curl 命令:

    $ curl -v -H "Transfer-Encoding: chunked" -H "Content-Type: application/x-www-form-urlencoded" -d "step=4&install_phpsso=1&sso%5Bsso_url%5D=http%3A%2F%2F127.0.0.1%2Fphpsso_server%2F&sso%5Busername%5D=&sso%5Bpassword%5D=&selectmod%5B%5D=announce&selectmod%5B%5D=comment&selectmod%5B%5D=link&selectmod%5B%5D=vote&selectmod%5B%5D=message&selectmod%5B%5D=mood&selectmod%5B%5D=poster&selectmod%5B%5D=formguide&selectmod%5B%5D=wap&selectmod%5B%5D=upgrade&selectmod%5B%5D=tag&selectmod%5B%5D=sms&testdata=1" http://examples.com/install/install.php?
    

    在不借助各种反代服务器,直接访问后端的服务器,在测试返回的数据中可以看到进行到了安装的第五步

    但在测试提交不成功返回的 response,是直接中断了输出:

    *   Trying 111.202.85.44...
    * Connected to examples.com (111.202.85.44) port 80 (#0)
    > POST /install/install.php? HTTP/1.1
    > Host: examples.com
    > User-Agent: curl/7.49.1
    > Accept: */*
    > Transfer-Encoding: chunked
    > Content-Type: application/x-www-form-urlencoded
    >
    > 190
    * upload completely sent off: 407 out of 400 bytes
    < HTTP/1.1 200 OK
    < Server: nginx
    < Connection: keep-alive
    < Date: Fri, 28 Oct 2016 18:19:01 GMT
    < Content-Type: text/html; charset=utf-8
    < Transfer-Encoding: chunked
    < Keep-Alive: timeout=60
    < Vary: Accept-Encoding
    < Vary: Accept-Encoding
    < X-Daa-Tunnel: hop_count=1
    <
    * Recv failure: Connection reset by peer
    * Closing connection 0
    curl: (56) Recv failure: Connection reset by peer
    

    如果把post 过去表单的值减少到几个,那么这些反代服务器都能正确返回数据。

    8 条回复    2016-10-29 23:35:58 +08:00
    vibbow
        1
    vibbow  
       2016-10-28 19:33:59 +08:00 via Android
    可以用 caddy 啊
    billlee
        2
    billlee  
       2016-10-28 20:12:16 +08:00
    proxy.inc 是什么内容?
    iCodex
        3
    iCodex  
    OP
       2016-10-28 23:30:31 +08:00
    @billlee 就几行:

    ```
    proxy_redirect off;
    proxy_set_header Accept-Encoding '';
    proxy_set_header Host $host;
    proxy_set_header Referer $http_referer;
    proxy_set_header Cookie $http_cookie;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    ```
    CRVV
        4
    CRVV  
       2016-10-29 08:57:23 +08:00 via Android
    谁教你设 fastopen=256 的?
    iCodex
        5
    iCodex  
    OP
       2016-10-29 12:16:59 +08:00 via Android
    @CRVV 不加也不影响测试啊
    iCodex
        6
    iCodex  
    OP
       2016-10-29 12:20:26 +08:00 via Android
    @CRVV 配置里还有个 SSL 监听的,后来没删除。可就是我删除了依然没法通过测试
    binghe
        7
    binghe  
       2016-10-29 18:29:25 +08:00
    请问这是什么字体???

    iCodex
        8
    iCodex  
    OP
       2016-10-29 23:35:58 +08:00 via Android
    @binghe Monaco
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1167 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 71ms · UTC 18:28 · PVG 02:28 · LAX 10:28 · JFK 13:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.