0

I'm using nginx as reverse proxy for my VMs. When I try to authenticate myself in a my website, or in phpmyadmin, nginx return the reponse from the local IP when the POST is from a domain!

Look: Nginx return a local IP instead the domain name

Here i'm trying to authenticate to phpmyadmin. When I valid, I have to refresh the page to connect successfully.

This is my nginx configuration:

server {
    listen 80;
    server_name     mysql.mydomain.com;
    location / {
            proxy_pass      http://10.0.2.103;
    }
}

My default file is:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        location / {
                try_files $uri $uri/ =404;
                proxy_set_header    Host                $http_host;
                proxy_set_header    X-Real-IP           $remote_addr;
#               proxy_set_header    X-Forwarded-Ssl     on;
                proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
                fastcgi_param REMOTE_ADDR $http_x_real_ip;

                proxy_set_header    X-Forwarded-Proto   $scheme;
                proxy_set_header    X-Frame-Options     SAMEORIGIN;
        }

        # Pour let's encrypt
        location '/.well-known/acme-challenge' {
                default_type "text/plain";
                root         /root/certbot-auto/;
        }

        # On interdit tout autre appel
        location ~ /\. {
                deny all; access_log off; log_not_found off;
        }
}

I'm using CloudFlare for SSL certification. If needed, I can use Let's Encrypt with Nginx. Apache is using for Phpmyadmin, and the other services on other VMs.

I search on internet since yesterday morning, but I didn't found anything about this kind of problem. Do you know what is going wrong ?

poka
  • 135
  • 3
  • 13
  • Your question is imprecise. Can you edit your question to show an example of something not working? For example you could add a curl showing what happens, describe what you expect to happen, and show any applicable logs - web server access, error, and back end system. – Tim Jul 13 '17 at 22:38
  • Excuse me but I don't know which log I could show you ... I'm not very good this nginx, could you please give me a command I can make ? – poka Jul 13 '17 at 23:04

1 Answers1

0

This doesn't have anything to do with nginx actually.

When you do a POST request to log-in to PHPMyAdmin, PHPMyAdmin sends back a 302 redirect to the index.php page, which causes your browser to try to load page from wrong address.

So, you have to fix the base URL setting in PHPMyAdmin, so that it will generate correct URLs with correct domain name.

The setting you need to add to PHPMyAdmin configuration is:

$cfg['PmaAbsoluteUri'] = 'https://mysql.example.com/';

This option is documented in https://docs.phpmyadmin.net/en/latest/config.html#basic-settings.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Ok, you should be right, but the thing is, I didn't touch anything in the configuration of phpmyadmin. Why does he make that ? – poka Jul 13 '17 at 22:52
  • Also, the problem is only when I try to log in. Then, the page is looping just on the POST and GET request I shown to you. So here when I refresh the page, it's ok i'm authenticate to phpmyadmin with no probleme... And this problem is same with another website in another VM of my server. Completely another website, and just when I try to log in again... – poka Jul 13 '17 at 23:00
  • When you are running through a proxy, PHPMyAdmin thinks it is reachable at the same address as its local address is. This is true when there is no proxy in front of PHPMyAdmin. However, when proxy is added in front of it, the situation changes. What comes to your application, the same thing happens there. It generates URLs in its responses with its own hostname, which is not reachable when a reverse proxy is used. You should change the application so that it generates proper URLs. – Tero Kilkanen Jul 13 '17 at 23:45
  • I added the exact setting information to my answer. – Tero Kilkanen Jul 13 '17 at 23:50
  • Ok I copy config.sample.inc.php to config.inc.php, puted the line: `$cfg['PmaAbsoluteUri'] = 'https://mysql.example.com/';` I reloaded apache, but nothing changed. Did I forget something ? Should I reinstall phpmyadmin ? – poka Jul 14 '17 at 00:36
  • It is hard to tell without seeing the setup itself. Reinstall won't help because the default setup is for without reverse proxies. – Tero Kilkanen Jul 14 '17 at 09:44
  • But if I understand, if I stop de SSL with CoudFlare, and certificate with Let's Encrypt and Nginx, that should resolve the problem ? Without touch the phpmyadmin config ? – poka Jul 14 '17 at 12:09
  • You never mentioned CloudFlare in your original question, which is an important piece of information. It is impossible to give any answers since there is so little information on your setup. – Tero Kilkanen Jul 14 '17 at 15:54
  • Ok sorry, I didn't think it was important for this problem. I added it in my post. – poka Jul 16 '17 at 10:27
  • That solved my problem for phpmyadmin! Thank you! But now I have the same kind of probleme with my shoutbox in another website, on the same server. But here I don't know how to force the domain name instead local IP ... – poka Jul 18 '17 at 13:35