Solved

moving from nginx to varnish

Posted on 2013-11-25
5
285 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

820 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