Solved

moving from nginx to varnish

Posted on 2013-11-25
5
283 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
ID: 39675654
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
ID: 39676846
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
ID: 39938005
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
ID: 39939209
thank you very much
0
 
LVL 26

Expert Comment

by:arober11
ID: 39940923
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

832 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