Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

moving from nginx to varnish

Posted on 2013-11-25
5
Medium Priority
?
296 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 2000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

972 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