Varnish serving incorrect Apache document root

Keywords: LAMP/MAMP/WAMP - Linux - Technical issue - Other
bnsupport ID: f2591734-ec9c-0ff9-8ef6-8d4f92a74794
Description:
I’ve found a few other topics here on this subject, but none seem to offer a fix for my problem. Hopefully someone has more insight than I do…

I am trying to move my LAMP site to be served from varnish.

Up to now, I’ve been using port 80 for apache as usual. I also defined the default virtual host in /opt/bitnami/apache/conf/bitnami/bitnami.conf" so that apache serves my app as the document root.

Following the bitnami instructions, I have switched things so that varnish listens on port 80, which apache is now on port 81. I followed the bitnami varnish instructions correctly, I’m almost sure.

At this point, I can see my site perfectly if I browse on port 81.

However, and here’s the problem, if I browse on port 80, via varnish, the document root is now the bitnami welcome index.html page. My site is only available by prepending the path to the app in the url.

It seems that varnish isn’t recognizing the virtual host that I defined in /opt/bitnami/apache/conf/bitnami/bitnami.conf". (For the record, I updated the port in this file to 81, as well, as per the instructions.

Ideally, I’d like to force varnish to recognize the default virtual host I set up in apache. However, another workaround is possible: I’m only serving a single site off this machine, so I don’t believe I need the default virtual host. However, I couldn’t find another way to set the apache document root.

Thanks in advance for any help!

Hi @mefron,

I just reviewed the Apache’s and Varnish’s configuration and it looks fine. Let’s see if there is any redirection in place that is causing the difference between the data you receive.

curl -LI localhost:81
curl -LI localhost

I only saw a misconfiguration between the /opt/bitnami/apache/conf/bitnami/bitnami.conf and /opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf, the “DocumentRoot” line is not updated in the second file but that shoudn’t be a problem unless you use https.

The LAMP installation already has default virtual hosts, they are the ones you can find in the files I mentioned above.

Thanks

Thanks for your help!

Here’s the output of those curl invocations:

bitnami@ip-172-26-10-232:~$ curl -LI localhost:81
HTTP/1.1 200 OK
Date: Mon, 19 Apr 2021 15:17:11 GMT
Server: Apache/2.4.46 (Unix) OpenSSL/1.1.1d
Last-Modified: Tue, 09 Feb 2021 18:44:44 GMT
ETag: "12f3-5baebae113f00"
Accept-Ranges: bytes
Content-Length: 4851
Vary: Accept-Encoding
Content-Type: text/html

bitnami@ip-1xxxx:~$ 
bitnami@ip-1xxxx:~$ curl -LI localhost
HTTP/1.1 200 OK
Date: Mon, 19 Apr 2021 15:17:22 GMT
Server: Apache/2.4.46 (Unix) OpenSSL/1.1.1d
Last-Modified: Tue, 09 Feb 2021 18:44:44 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 32788
Age: 0
Via: 1.1 varnish (Varnish/6.5)
ETag: W/"12f3-5baebae113f00-gzip"
Accept-Ranges: bytes
Content-Length: 4851
Connection: keep-alive

I hadn’t changed the document root in the ssl conf file since I’m not using ssl (yet). But I did just make that change. No effect–no surprise.

oops. apologies for the mangled formatting in that post.

Hi @mefron,

I do not see anything strange in the curl outputs. As you can see, the request to port 81 is managed by Apache and the request to the port 80 is served by Varnish. I just accessed your site (****tapes.org, using http and https) and they both worked properly. Did you undo the configuration changes?

Sorry, I may have been unclear. Eventually things will end up on that .org domain. But for now, the dev instance I’m working on is here: http://3.223.97.126.

You can see what is supposed to be the default vhost (i.e. the document root) at http://3.223.97.126:81.

I tried a few permutations of moving various directories and variables around but still haven’t been able to get varnish to understand that the directory I list in the default vhost file is supposed to be the document root for the server.

Hi @mefron,

Both ports are giving me the same information

I understood you were getting a different information when accessing port 80. Did you manage to solve it?

I must have been working on the site when you visited. At that point I had tried to monkey with apache’s document root variable, which allowed varnish to serve my home page correctly (as you saw), but with none of the link working (they all returned 404s).

I’m reverting to the state it was in when I ran the diagnostic script. You’ll now see the split brain between ports 80 and 81.

One thought I had: this is a drupal site. For complicated reasons, I implemented it on the bitnami LAMP stack, not the bitnami drupal stack. I noticed the vhost stuff is slightly different on the drupal stack. Is there any documentation out there on applying varnish on the drupal stack? I noticed that it doesn’t seem to come with varnish in the stack, as the LAMP images do. Maybe it would be easier for me to get this working in that environment?

hi @mefron,

I’ve been reviewing your configuration files again and I do not find the cause of this behavior in your installation.

You can follow this guide where we explain how to deploy a custom PHP application on top of the LAMP solution to see if that solves the problem

https://docs.bitnami.com/aws/infrastructure/lamp/administration/create-custom-application-php/

Note: if you are going to configure your domain in that new virtualhost, you will probably need to recover the ServerName value in the httpd.conf so there are no conflicts with the new virtualhost configuration

203c203
< ServerName www.lbjtapes.com:81
---
> ServerName www.example.org:81

Once you finish with these changes, please run the Bitnami support tool again so I can review them. :slight_smile:

Thanks