Solved

moving from nginx to varnish

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux boot fsck problem 3 61
exchange 2010 turning off 3des ciphers 2 100
http to https 3 38
Video Streaming 6 54
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

932 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

10 Experts available now in Live!

Get 1:1 Help Now