0

Last week I installed Varnish and my websites are now working fine with it - I can navigate and change them without error. Back when I installed it, I putted Varnish on port 80 and moved Apache to port 8080.

I later noticed that if I run the following in my browser I can't access phpmyadmin:

MY_IP:80/phpmyadmin MY_IP:8080/phpmyadmin

Yet, if I move phpmyadmin to say /var/www/html/site_dir/phpmyadmin I can indeed access it without a problem via domain.tld/phpmyadmin

But here's something strange, it now seems that nothing with an IP_ADDRESS works, not even the site which works without it in the browser:

MY_IP/domain.tld MY_IP/domain.tld/phpmyadmin MY_IP:8080/domain.tld/phpmyadmin

My question is why couldn't I access anything in server with an IP besides the Apache index.html page, from any browser?


The way I installed Varnish is this:

cd ~
apt-get update && apt-get install varnish -y
sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf
sed -i 's/\*\:80/\*\:8080/g' /etc/apache2/sites-available/000-default.conf
sed -i 's/\*\:80/\*\:8080/g' /etc/apache2/sites-available/domain.tld.conf && domain.tld.conf
mkdir -p /etc/systemd/system/varnish.service.d # Be aware! You might not need this in the future.
cat <<-'VARNISH' > /etc/systemd/system/varnish.service.d/customexec.conf
    [Service]
    ExecStart=
    ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
VARNISH
systemctl restart apache2.service && systemctl daemon-reload && systemctl restart varnish.service
1

This is (relatively) normal behavior.

Your Apache config is configured to serve /var/www/html/site_dir from your domain. This means that you can not actually access anything not in this directory when you're pinging your site from your domain. If you want to access PHPmyAdmin from the domain name, you'll have to move it to site_dir, or change your webroot to /var/www/html and move all of your other files.

Alternatively, you can make a new virthost for PHPmyAdmin with its own domain name, like so:

<VirtualHost pma.example.com:8080>
    ServerName pma.example.com

    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/html/phpmyadmin/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    [ anything else ... ]
</VirtualHost>

As for why you can't access anything by your IP address, it's because your virthost for your domain is configured to, well, your domain. When Apache can't match any of your virthosts, it falls back to 000_default, which does not have a set ServerName and listens to everything. If you want your website to always be accessed (by IP or whatever), you will need to configure your current virthost in the same way that 000_default is configured (or just reconfigure 000_default and disable your custom virthost). Or, create a new virthost that matches your IP.

If you want to have your IP address as a "back door" to management things like PHPmyAdmin and everything else stored in /var/www/html, you can set that up by making sure the DocumentRoot is /var/www/html. Note, however, that this will introduce a minor security threat, especially if you're hosting multiple domains from your website.

  • Hi Kaz, and thanks. I'm not sure I understand the saying: "change your webroot to /var/www/html and move all of your other files.". Will you please elaborate or try to clarify a bit? – JohnDoea May 18 '17 at 2:51
  • I didn't change my document root, just the ports, so AFAIK, it should be /var/www/html naturally. – JohnDoea May 18 '17 at 2:54
  • I read the last paragraph in the answer twice but I think I miss some specific knowledge to fully understand it. If I'm not wrong, what you described was the situation for me until this day: I always install PMA with a timeout in a self-killing tmux session so I don't know why this situation holds any security threat. – JohnDoea May 18 '17 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.