免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6623 | 回复: 3
打印 上一主题 下一主题

[proxy] 【待解决】varnish + Nginx做透明代理不支持https [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-06-25 11:40 |只看该作者 |倒序浏览
本帖最后由 心若寒江雪 于 2013-06-25 11:41 编辑

如题,我使用varnish + Nginx做了一个透明代理,但是当我访问https网站的时候就报400的错误,请大侠指教:
nginx.conf

  1.   server {
  2.     listen 8080 default_server;
  3.     server_name _;

  4.     access_log  /data/nginx/logs/access.log  access;
  5.     location ~* \.(gif|png|jpg|jpeg|wmv|avi|mpg|mpeg|mp4|htm|html|js|css|mp3|swf|ico|flv)$ {
  6.       proxy_set_header X-Real-IP $remote_addr;
  7.       proxy_store /data/nginx/cache$uri;
  8.       proxy_store_access user:rw group:rw all:r;
  9.       proxy_pass $scheme://$host;
  10.       add_header request_uri $request_uri;
  11.     }
  12.     location / {
  13.       proxy_pass $scheme://$host;
  14.       include fastcgi.conf;
  15.     }
  16.   }
复制代码
varnish: default.vcl
  1. backend default {
  2. .host = "127.0.0.1";
  3. .port = "8080";
  4. }
  5. sub vcl_deliver {
  6.       set resp.http.yougou-hits = obj.hits ;
  7.       if (obj.hits > 0) {
  8.             set resp.http.yougou-varnish = "HIT";
  9.       } else {
  10.             set resp.http.yougou-varsish= "MISS";
  11.       }
  12. }

  13. sub vcl_recv {
  14.     if (req.restarts == 0) {
  15.       if (req.http.x-forwarded-for) {
  16.           set req.http.X-Forwarded-For =
  17.               req.http.X-Forwarded-For + ", " + client.ip;
  18.       } else {
  19.           set req.http.X-Forwarded-For = client.ip;
  20.       }
  21.     }
  22.     if (req.request != "GET" &&
  23.       req.request != "HEAD" &&
  24.       req.request != "PUT" &&
  25.       req.request != "POST" &&
  26.       req.request != "TRACE" &&
  27.       req.request != "OPTIONS" &&
  28.       req.request != "DELETE") {
  29.       /* Non-RFC2616 or CONNECT which is weird. */
  30.       return (pipe);
  31.     }
  32.     if (req.request != "GET" && req.request != "HEAD") {
  33.         /* We only deal with GET and HEAD by default */
  34.         return (pass);
  35.     }
  36.     if (req.http.Authorization || req.http.Cookie) {
  37.         /* Not cacheable by default */
  38.         return (pass);
  39.     }
  40.     return (pass);
  41. }
复制代码
当我访问 https://www.google.com.hk的时候
  1. 127.0.0.1 - - [25/Jun/2013:11:38:45 +0800] "CONNECT www.google.com.hk:443 HTTP/1.1" 400 172 "-" "-" -http8080
  2. 127.0.0.1 - - [25/Jun/2013:11:38:45 +0800] "CONNECT www.google.com.hk:443 HTTP/1.1" 400 172 "-" "-" -http8080
复制代码
找到的一个连接(http://www.reistlin.com/2011/04/page/1/)里面说:
“因为 Nginx 不支持 CONNECT,所以无法正向代理 Https 网站(网上银行,Gmail)”
但是我不怎么理解,请大侠指教

论坛徽章:
0
2 [报告]
发表于 2013-06-25 16:29 |只看该作者
@各种版主lol

论坛徽章:
0
3 [报告]
发表于 2013-06-25 18:17 |只看该作者
帮顶lollollollollollol

论坛徽章:
0
4 [报告]
发表于 2013-11-23 10:54 |只看该作者
出现400错误是因为varnish认为客户端请求header行数及长度过大,其默认最大接受的请求header行数为64,最大长度(所有请求header行长度之和)为2048,而https的请求头超过了默认长度从而导致400错误,解决这个问题比较简单,在varnish启动参数中加入:

-p http_max_hdr=256

-p http_req_hdr_len=8192

再重启varnish, 即可解决其400错误。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP