Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure varnish

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to configure varnish". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure varnish.

Server1:172.25.254.20 varnish

Server2:172.25.254.21 http

Host: 172.25.254.44

Varnish is a high performance open source HTTP accelerator.

On server1:

# yum install varnish-3.0.5-1.el6.x86_64.rpm varnish-libs-3.0.5-1.el6.x86_64.rpm-y

# vim / etc/varnish/default.vcl

Backend web1 {

.host = "127.0.0.1"

.port = "8080"

} # define native port

Sub vcl_deliver {

If (obj.hits > 0) {

Set resp.http.X-Cache = "HIT from westos cache"

}

Else {

Set resp.http.X-Cache = "MISS from westos cache"

}

Return (deliver)

} # define whether to hit or not

# yum install httpd-y

# cd / var/www/html

# echo server20.example.com > index.html

# vim / etc/httpd/conf/httpd.conf

# Listen 12.34.56.78:80

Listen 8080 # modifies http ports to prevent conflicts with varnish ports

# / etc/init.d/httpd start

# netstat-antlp # check whether the http 8080 port is open

# vim / etc/sysconfig/varnish

VARNISH_LISTEN_PORT=80 # varnish Port

# / etc/init.d/varnish start

[root@server20 html] # iptables-L

Chain INPUT (policy ACCEPT)

Target prot opt source destination

Chain FORWARD (policy ACCEPT)

Target prot opt source destination

Chain OUTPUT (policy ACCEPT)

Target prot opt source destination # check to see if the local fire wall is closed

[root@foundation44 Desktop] # curl-I 172.25.254.20

HTTP/1.1 404 westos cache

Server: Varnish

Content-Type: text/html; charset=utf-8

Retry-After: 5

Content-Length: 398

Accept-Ranges: bytes

Date: Wed, 29 Jun 2016 10:11:45 GMT

X-Varnish: 1112141971

Age: 0

Via: 1.1 varnish

Connection: close

X-Cache: MISS from westos cache # is not hit at this time, which means there is no cache

[root@foundation44 Desktop] # curl-I 172.25.254.20

HTTP/1.1 404 westos cach

Server: Varnish

Content-Type: text/html; charset=utf-8

Retry-After: 5

Content-Length: 398

Accept-Ranges: bytes

Date: Wed, 29 Jun 2016 10:15:02 GMT

X-Varnish: 1112141972

Age: 0

Via: 1.1 varnish

Connection: close

X-Cache: HIT from westos cache # hits at this time, indicating that there is already a cache

# vim / etc/varnish/default.vcl

Backend web2 {

.host = "172.25.254.21"

.port = "80"

}

Director lb random {# aggregates multiple backends together

{.backend = web1

.weight = 1

}

{.backend = web2

.weight = 2

}

}

Sub vcl_recv {

If (req.http.host ~ "^ (www.)? westos.org") {

Set req.http.host = "www.westos.org"

Set req.backend = lb

Return (pass); # definition is not cached for convenience

} elsif (req.http.host ~ "^ bbs.westos.org") {

Set req.backend = web2

} else {

Error 404 "westos cache"

}

} # if you visit another, you will report an error of 404

# / etc/init.d/varnish reload

Operations performed on server2

Yum install httpd-y

# cd / var/www/html

# echo server21.example.com > index.html

# / etc/init.d/httpd start

# vim / etc/httpd/conf/httpd.conf

NameVirtualHost *: 80

DocumentRoot / var/www/html

ServerName www.westos.org

Serveralias westos.org

DocumentRoot / var/www/virtualhost/bbs

ServerName bbs.westos.org

# mkdir-p / var/www/virtualhost/bbs

# cd / var/www/virtualhost/bbs/

# echo bbs.example.com > index.html

# / etc/init.d/httpd restart

# vim / etc/httpd/conf/httpd.conf

# / etc/init.d/httpd restart

Then add the relevant parsing on server1 and server2 on the host, access it by Firefox on the host, or use curl-I www.westos.org

At this point, I believe you have a deeper understanding of "how to configure varnish", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report