0
votes

I've been playing around with Varnish however I've encountered an issue that causes an infinite redirect loop on all my sites (Wordpress and Drupal mainly). Curl to localhost:8080 and setting the "Host" as a header outputs the correct html so it's not Nginx, however when curling to localhost (hitting varnish) the response is "301 Moved Permanently".

Any ideas?

Here's a vhost config for a site:

index index.php;
server {
        server_name www.example.com;
        rewrite ^ $scheme://example.com$request_uri? permanent;
}
server {
        listen   8080;
        server_name example.com;
        access_log /var/www/logs/access.log;
        error_log /var/www/logs/error.log;
        root /var/www/example.com/public_html;
        include global/restrictions.conf;

        location / {
                try_files $uri $uri/ /index.php;
                if (!-e $request_filename) {
                        rewrite ^/(.*)$ /index.php?q=$1 last;
                }
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/tmp/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
}

And the config for Varnish can be found here: https://github.com/mattiasgeniar/varnish-4.0-configuration-templates/blob/master/default.vcl except I've modified it slightly so the port is looking at 8080

Thanks

2

2 Answers

0
votes

I think you need listen 8080; into first server too:

server {
    listen   8080;
    server_name www.example.com;
    rewrite ^ $scheme://example.com$request_uri? permanent;
}
0
votes

If you are still looking for a working solution, you can use Varnish in a Docker container in the latest Plesk Onyx version.

Tutorial: https://www.plesk.com/blog/product-technology/varnish-wordpress-docker-container