Varnish configuration, solution to error 503

Source: Internet
Author: User
Tags varnish

First, let's talk about how to configure varnish.
The varnish startup requires the configuration file (*. VCL), and some other startup parameters (the specific parameters are omitted here, man will see everything ). My installation is Varnish-2.0.4
The installation process is as follows:

#./Configure -- prefix =/usr/local/varnish -- enable-developer-Waring -- enable-debugging-sybmbles -- enable-werror
# Make
# Make install

After compilation and installation are complete, start it. The Startup File I wrote is as follows:

### Start. Sh ######
#! /Bin/sh
# File: Start. Sh
Date-u
/Usr/local/Varnish/sbin/varnishd
-A 173.26.100.206: 80-s file,/Cache/Varnish/V, 1024 MB-F
/Usr/local/Varnish/etc/Varnish/Default. VCL-P thread_pool_max = 1500-P
Thread_pools = 5-P listen_depth = 512-P client_http11 = on-P
Connect_timeout = 1 s-p send_timeout = 20 s

The following is the deault. VCL Configuration:

###### Defualt. VCL ########
Backend default {
. Host = "173.26.100.206 ";
. Port = "81 ";
}

# Below is a commented-out copy of the default VCL logic. If you
# Redefine any of these subroutines, the built-in logic will be
# Appended to your code.

Sub vcl_recv {
If (req. Request! = "Get "&&
Req. Request! = "Head "&&
Req. Request! = "Put "&&
Req. Request! = "Post "&&
Req. Request! = "Trace "&&
Req. Request! = "Options "&&
Req. Request! = "Delete "){
/* Non-RFC2616 or connect Which is weird .*/
Return (PIPE );
}
If (req. Request! = "Get" & Req. Request! = "Head "){
/* We only deal with get and head by default */
Return (PASS );
}
If (req. http. Authorization | Req. http. Cookie ){
/* Not cacheable by default */
Return (PASS );
}
Return (lookup );
}

Sub vcl_pipe {
# Note that only the first request to the backend will have
# X-forwarded-for set. If you use X-forwarded-for and want
# Have it set for all requests, make sure to have:
# Set Req. http. Connection = "close ";
# Here. It is not set by default as it might break some broken Web
# Applications, like IIS with NTLM authentication.
Return (PIPE );
}

Sub vcl_pass {
Return (PASS );
}

Sub vcl_hash {
Set Req. Hash + = Req. url;
If (req. http. HOST ){
Set Req. Hash + = Req. http. Host;
} Else {
Set Req. Hash + = server. IP;
}
Return (hash );
}

Sub vcl_hit {
If (! OBJ. cacheable ){
Return (PASS );
}
Return (deliver );
}

Sub vcl_miss {
Return (FETCH );
}

Sub vcl_fetch {
If (! OBJ. cacheable ){
Return (PASS );
}
If (obj. http. Set-cookie ){
Return (PASS );
}
Set obj. prefetch =-30 s;
Return (deliver );
}

Sub vcl_deliver {
Return (deliver );
}

Sub vcl_discard {
/* XXX: Do not redefine vcl_discard {}, it is not yet supported */
Return (discard );
}

Sub vcl_prefetch {
/* XXX: Do not redefine vcl_prefetch {}, it is not yet supported */
Return (FETCH );
}

Sub vcl_timeout {
/* XXX: Do not redefine vcl_timeout {}, it is not yet supported */
Return (discard );
}

Sub vcl_error {
Set obj. http. Content-Type = "text/html; charset = UTF-8 ";
Synthetic {"
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<HTML>
<Head>
<Title> "} obj. Status" "obj. Response {" </title>
</Head>
<Body>
<H1> error "} obj. Status" "obj. Response {" <P> "} obj. Response {" </P>
<H3> guru meditation: <P> Xid: "} Req. Xid {" </P>
<Address>
<A href = "http://www.varnish-cache.org/"> varnish </a>
</Address>
</Body>
</Html>
"};
Return (deliver );
}

For example
Run./start. Sh to start varnish to listen to port 80 of the local machine, and backend to port 81 of the Apache listening. The problem occurs. Access through port 81.
Frequently responding, the browser obtains the correct page, and accesses port 81 With a 503 error. Many methods have been searched on the Internet to solve this problem. Many ways are to modify and add in the configuration file:

Backend default {
. Host = "173.26.100.206 ";
. Port = "81 ";
### Add configuration in the following three actions
. Connect_timeout = 1 s;
. First_byte_timeout = 5S;
. Between_bytes_timeout = 2 S;
}

As a matter of fact, it didn't work. I had to work on it for a long time. I accidentally removed some startup options in start. Sh, and found that I could respond normally.
The new startup file is as follows:

#### Start. Sh #####
#! /Bin/sh
# File: Start. Sh
Date-u
/Usr/local/Varnish/sbin/varnishd
-A 173.26.100.206: 80-s file,/Cache/Varnish/V, 1024 MB-F
/Usr/local/Varnish/etc/Varnish/Default. VCL-P thread_pool_max = 1500-P
Thread_pools = 5-P listen_depth = 512-P client_http11 = on

Connect_timeout and send_timeout are removed, which is equivalent to the default system configuration.

As a result, varnish once again showed high-speed HTTP proxy capabilities.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.