0

I have an application on my server that is for the most part overwriting Apache. Now I want to install PhpMyAdmin on my VPS, it doesn't work (displays directory listing instead of UI), but by asking around on few sites plus some trial and error I realized I'm trying to run PhpMyAdmin through my application (Traccar) instead through Apache.

Now back to the topic. I'm on Ubuntu Server 18.04 and I have the following site configuration:

Listen 80
<IfModule mod_ssl.c>
    <VirtualHost *:80>
        ServerName x.example.com
        Redirect / https://x.example.com
    </VirtualHost>

    <VirtualHost *:443>
        ServerName x.example.com

        DocumentRoot /var/www/html
        ServerAdmin admin@localhost

        ProxyPass /api/socket ws://localhost:app_port/api/socket
        ProxyPassReverse /api/socket ws://localhost:app_port/api/socket

        ProxyPass /phpmyadmin !

        ProxyPass / http://localhost:app_port/
        ProxyPassReverse / http://localhost:app_port/

        SSLEngine on
        SSLOptions +StrictRequire
        SSLProtocol TLSv1
        ServerAlias x.example.com
        SSLCertificateFile /etc/letsencrypt/live/x.example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/x.example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
</IfModule>

The way I want it to work:

If I connect to x.example.com I get redirected to my application. Works properly.

If I connect to x.example.com/phpmyadmin I want to receive PhpMyAdmin UI. I receive a "too many redirects" error instead.

When I access phpmyadmin directory the rewrite log keeps alternating between these two messages in the server log:

[Fri May 10 10:32:38.733370 2019] [rewrite:trace1] [pid 19228] mod_rewrite.c(482): [client xxx.xxx.xxx.xxx:yyyy] xxx.xxx.xxx.xxx - - [x.example.com/sid#7f34cd331cc0][rid#7f34cd2640a0/initial] pass through /phpmyadmin
[Fri May 10 10:32:38.767398 2019] [rewrite:trace2] [pid 19228] mod_rewrite.c(482): [client xxx.xxx.xxx.xxx:yyyy] xxx.xxx.xxx.xxx - - [x.example.com/sid#7f34cd331cc0][rid#7f34cd2620a0/initial] init rewrite engine with requested uri /phpmyadmin

This is what I receive when I wget to x.example.com/phpmyadmin:

--2019-05-10 10:43:19--  https://x.example.com/phpmyadmin
Resolving x.example.com (x.example.com)... 217.182.76.36
Connecting to x.example.com (x.example.com)|217.182.76.36|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://x.example.com/phpmyadmin [following]
--2019-05-10 10:43:19--  https://x.example.com/phpmyadmin
Reusing existing connection to x.example.com:443.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://x.example.com/phpmyadmin [following]
--2019-05-10 10:43:19--  https://x.example.com/phpmyadmin
Reusing existing connection to x.example.com:443.

The lines repeat until they reach 20 redirections.

If I curl to x.example.com/phpmyadmin I get this:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
    <title>302 Found</title>
</head>
<body>
    <h1>Found</h1>
    <p>The document has moved <a href="https://x.example.comphpmyadmin">here</a>.</p>
    <hr>
    <address>Apache/2.4.29 (Ubuntu) Server at x.example.com Port 80</address>
</body>
</html>
  • 1
    Check the server logs for more detail on what is causing the redirects. (On a side note, consider running phpMyAdmin on its own subdomain rather where you can more easily implement additional access controls as well. ). – HBruijn May 9 at 13:22
  • Unfortunately I won't be able to do it until tomorrow. I hope it won't be too late for a response. – xtl May 9 at 14:43
  • Where do I look for logs? I looked at apache logs and in "other_vhosts_access" I found over 10 "GET /phpmyadmin" connections in the exact same second. It's definitely me, although this error log doesn't tell me much about what I could be doing wrong – xtl May 10 at 5:38
  • 1
    I just remembered something stupid. I forgot back when I started installing the SSL certificate I didn't know very well what I was doing, my redirects wouldn't work etc. Basically I forgot I left a permament redirect rule in my apache2.conf - this caused an infinite loop. Deleting that line from apache config fixed my problem. Thanks to everyone involved. – xtl May 10 at 10:30
  • 1
    Please post your solution as an answer and accept it ... otherwise the question will pop up again and again in the future because it isn't answered. – Gerald Schneider May 10 at 10:31
1

The answer is incredibly simple. I forgot I left a permament redirect rule in my apache2.conf - this caused the infinite loop. Deleting that line from apache config fixed my problem. Thanks to everyone involved.

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.