3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
<html xmlns="http://www.w3.org/1999/xhtml">
8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10
<title>HTTP — Varnish version 3.0.2 documentation</title>
11
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
<script type="text/javascript">
14
var DOCUMENTATION_OPTIONS = {
17
COLLAPSE_INDEX: false,
22
<script type="text/javascript" src="../_static/jquery.js"></script>
23
<script type="text/javascript" src="../_static/underscore.js"></script>
24
<script type="text/javascript" src="../_static/doctools.js"></script>
25
<link rel="top" title="Varnish version 3.0.2 documentation" href="../index.html" />
26
<link rel="up" title="Frequently asked questions" href="index.html" />
27
<link rel="next" title="Configuration" href="configuration.html" />
28
<link rel="prev" title="General questions" href="general.html" />
34
<li class="right" style="margin-right: 10px">
35
<a href="../genindex.html" title="General Index"
36
accesskey="I">index</a></li>
38
<a href="configuration.html" title="Configuration"
39
accesskey="N">next</a> |</li>
41
<a href="general.html" title="General questions"
42
accesskey="P">previous</a> |</li>
43
<li><a href="../index.html">Varnish version 3.0.2 documentation</a> »</li>
44
<li><a href="index.html" accesskey="U">Frequently asked questions</a> »</li>
48
<div class="document">
49
<div class="documentwrapper">
50
<div class="bodywrapper">
53
<div class="section" id="http">
54
<h1>HTTP<a class="headerlink" href="#http" title="Permalink to this headline">¶</a></h1>
55
<p><strong>What is the purpose of the X-Varnish HTTP header?</strong></p>
56
<p>The X-Varnish HTTP header allows you to find the correct log-entries for the transaction. For a cache hit, X-Varnish will contain both the ID of the current request and the ID of the request that populated the cache. It makes debugging Varnish a lot easier.</p>
57
<p><strong>Does Varnish support compression?</strong></p>
58
<p>This is a simple question with a complicated answer; see <a class="reference external" href="http://varnish-cache.org/wiki/FAQ/Compression">WIKI</a>.</p>
59
<p><strong>How do I add a HTTP header?</strong></p>
60
<p>To add a HTTP header, unless you want to add something about the client/request, it is best done in vcl_fetch as this means it will only be processed every time the object is fetched:</p>
61
<div class="highlight-python"><pre>sub vcl_fetch {
62
# Add a unique header containing the cache servers IP address:
63
remove beresp.http.X-Varnish-IP;
64
set beresp.http.X-Varnish-IP = server.ip;
66
set beresp.http.Foo = "bar";
69
<p><strong>How can I log the client IP address on the backend?</strong></p>
70
<p>All I see is the IP address of the varnish server. How can I log the client IP address?</p>
71
<p>We will need to add the IP address to a header used for the backend request, and configure the backend to log the content of this header instead of the address of the connecting client (which is the varnish server).</p>
72
<p>Varnish configuration:</p>
73
<div class="highlight-python"><pre>sub vcl_recv {
74
# Add a unique header containing the client address
75
remove req.http.X-Forwarded-For;
76
set req.http.X-Forwarded-For = client.ip;
80
<p>For the apache configuration, we copy the "combined" log format to a new one we call "varnishcombined", for instance, and change the client IP field to use the content of the variable we set in the varnish configuration:</p>
81
<div class="highlight-python"><pre>LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined</pre>
83
<p>And so, in our virtualhost, you need to specify this format instead of "combined" (or "common", or whatever else you use):</p>
84
<div class="highlight-python"><pre><VirtualHost *:80>
85
ServerName www.example.com
87
CustomLog /var/log/apache2/www.example.com/access.log varnishcombined
89
</VirtualHost></pre>
91
<p>The [<a class="reference external" href="http://www.openinfo.co.uk/apache/index.html">http://www.openinfo.co.uk/apache/index.html</a> mod_extract_forwarded Apache module] might also be useful.</p>
98
<div class="sphinxsidebar">
99
<div class="sphinxsidebarwrapper">
100
<h4>Previous topic</h4>
101
<p class="topless"><a href="general.html"
102
title="previous chapter">General questions</a></p>
104
<p class="topless"><a href="configuration.html"
105
title="next chapter">Configuration</a></p>
107
<ul class="this-page-menu">
108
<li><a href="../_sources/faq/http.txt"
109
rel="nofollow">Show Source</a></li>
111
<div id="searchbox" style="display: none">
112
<h3>Quick search</h3>
113
<form class="search" action="../search.html" method="get">
114
<input type="text" name="q" size="18" />
115
<input type="submit" value="Go" />
116
<input type="hidden" name="check_keywords" value="yes" />
117
<input type="hidden" name="area" value="default" />
119
<p class="searchtip" style="font-size: 90%">
120
Enter search terms or a module, class or function name.
123
<script type="text/javascript">$('#searchbox').show(0);</script>
126
<div class="clearer"></div>
128
<div class="related">
131
<li class="right" style="margin-right: 10px">
132
<a href="../genindex.html" title="General Index"
135
<a href="configuration.html" title="Configuration"
138
<a href="general.html" title="General questions"
140
<li><a href="../index.html">Varnish version 3.0.2 documentation</a> »</li>
141
<li><a href="index.html" >Frequently asked questions</a> »</li>
145
© Copyright 2010, Varnish Project.
146
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
b'\\ No newline at end of file'