Solved

moving from nginx to varnish

Posted on 2013-11-25
5
277 Views
Last Modified: 2014-03-19
Hello all,
I've a question: I really new to varnish (and also nginx). today my boss asked me to move the rules we currently have with reverse proxy nginx to varnish. we have a big number of redirect like:
              location = /gange {
                        rewrite ^(.*[^/])$ $1/ permanent;
                }

               location /gange {
                        proxy_pass http://www4-local/gange;
                        proxy_redirect default;
                        proxy_set_header Host $http_host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }

Open in new window


someone could help me how to write this code in VLC language?
thank you very much
Nick
0
Comment
Question by:nschwend
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Varnish 'doesn't' do redirects. But you can hack what looks like a redirect. Examples here
https://www.varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

...unless you want to redirect invisibly in the backend?
0
 

Author Comment

by:nschwend
Comment Utility
Hi Gary, thank you for your answer.. could you please write down the redirect I wrote in the question with this system?
what do you mean with  
...unless you want to redirect invisibly in the backend?
thank you
Nick
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
Comment Utility
Something like:

backend www4-local {
    .host = "www4-local";
    .port = "80";
}

sub vcl_recv {
 if(req.url ~ "^/gange") {
     if(req.url ~ "[^/]$") {
        set req.url = regsub(req.url, "$", "/");
        lookup;
    } 
 ....
}

sub vcl_fetch {
 if(req.url ~ "^/gange") {
            set req.http.X-Real-IP = client.ip;
            set req.backend = www4-local;

            if (req.http.x-forwarded-for) {
                set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
            } else {
                set req.http.X-Forwarded-For = client.ip;
            }
            remove req.http.Cookie;
   }

   ....
}

Open in new window

0
 

Author Closing Comment

by:nschwend
Comment Utility
thank you very much
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
You probably should move the following block from vcl_fetch  to vcl_recv:

            set req.http.X-Real-IP = client.ip;
            set req.backend = www4-local;

            if (req.http.x-forwarded-for) {
                set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
            } else {
                set req.http.X-Forwarded-For = client.ip;
            }

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now