Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:30:39+00:00 2026-05-29T07:30:39+00:00

I am trying to use Varnish as a reverse caching proxy for my nginx

  • 0

I am trying to use Varnish as a reverse caching proxy for my nginx install on Ubuntu 10.10, I have set up Varnish on port 8080 for testing and nginx is operating normally on port 80.

My nginx.conf:

user {user} {group};
worker_processes  16;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    client_max_body_size 4M;
    client_body_buffer_size 128k;
    access_log  /var/log/nginx/access.log;

    gzip        on;
    gzip_proxied any;
    gzip_comp_level 2;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml$

    sendfile        on;
    tcp_nopush     off;

    keepalive_timeout  30;
    tcp_nodelay        on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

My site’s .conf file:

server {
     listen  80;
     server_name www.mylesgray.com dev.mylesgray.com;

     access_log /var/www/mylesgray.com/logs/access.log;
     error_log /var/www/mylesgray.com/logs/error.log;

     location / {
        root /var/www/mylesgray.com/public;
        index index index.php;
        try_files $uri/ $uri index.php?q=$uri&$args;
        port_in_redirect off;
     }

     location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        access_log        off;
        expires           30d;
        root /var/www/mylesgray.com/public;
     }

     location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/mylesgray.com/public/$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    location ~ /.ht {
        deny  all;
    }

    location ~ /.git {
        deny  all;
    }

#    include /var/www/mylesgray.com/public/nginx.conf;
}

upstream backend {
    server 127.0.0.1:9000;
}

My Varnish conf:

backend default {
     .host = "localhost";
     .port = "80";
}

acl purge {
        "localhost";
}

sub vcl_recv {
        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                return(lookup);
        }

        if (req.url ~ "^/$") {
               unset req.http.cookie;
         }
}

sub vcl_hit {
        if (req.request == "PURGE") {
                set obj.ttl = 0s;
                error 200 "Purged.";
        }
}

sub vcl_miss {
        if (req.request == "PURGE") {
                error 404 "Not in cache.";
        }

        if (!(req.url ~ "wp-(login|admin)")) {
                        unset req.http.cookie;
        }

        if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?$
                unset req.http.cookie;
                set req.url = regsub(req.url, "\?.$", "");
        }

        if (req.url ~ "^/$") {
                unset req.http.cookie;
        }
}

sub vcl_fetch {
        if (req.url ~ "^/$") {
                unset beresp.http.set-cookie;
        }

        if (!(req.url ~ "wp-(login|admin)")) {
                unset beresp.http.set-cookie;
        }
}

So with all that when you goto my site on port 8080: http://www.mylesgray.com:8080 it just redirects to plain old: http://www.mylesgray.com What it should be doing instead is that (as it stands) if I access port 80 I should get nginx serving files only, and if I access 8080 I should have nginx + varnish serving files.

I’m doing this to test the performance benefits of varnish over plain nginx.

Any help much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:30:39+00:00Added an answer on May 29, 2026 at 7:30 am

    My best guess would be some kind of SEO plugin that’s thinking “oh a request on port 8080? That shouldn’t be, I’ll be kind and rewrite to port 80”:

    $ curl -I "http://www.mylesgray.com:8080/"
    HTTP/1.1 301 Moved Permanently
    Server: nginx/0.7.65
    Location: http://www.mylesgray.com/
    

    You may want to normalize your host headers by stripping the port numbers:

    set req.http.Host = regsub(req.http.Host, ":[0-9]+", "");
    

    If needed, have a look at some more examples at these configuration examples for Varnish

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying use a set of filter functions to run the appropriate routine,
I have been trying use the edit_post_link() function to contain an image. All of
I'm trying to use the sencha sdk to generate my minified file. I have
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a
I am trying use Thread but i have some problem (I am beginner at
Im trying to use esi to make a ninja caching on my site. The
I am trying use neo4j with Ruby on rails on Mac OSX. I have
I am trying use an iterator to go through a set and then do
I am trying use the mysql connector in c++ in ubuntu. It appears that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.