0

I'm using nginx in a separate LXC container as reverse proxy for all my Virtuals Machines and LXC containers. When I try to authenticate myself in a my website, for exemple phpmyadmin, or Yunohost, which are in separate VMs, 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;
        }
}

Apache is using on each VM for each services.

EDIT: I was using CloudFlare for SSL certification. Now i'm using Let's Encrypt with Nginx, and still same problem.

EDIT2: I solved the problem for phpmyadmin by forcing itself to use absolute URL, in the configuration file of phpmyadmin:

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

But the problem rest the same for my others services, in my other LXC container and Virtuals Machines.

When I try to connect to the URL agora.mydomain.com for the first time, wich is pointing to Yunohost, in a QEMU, this is what's happend: request agora.mydomain.com became local IP

My nginx VirtualHost is very simple:

server {
    listen 80;
    server_name     agora.mydomain.com;

    location / {
        proxy_pass      http://10.0.2.106;
#       return 301      https://agora.mydomain.com$request_uri;
    }
}

When using lynx localhost in local of the Yunohost VM, it's works, so that why I think it's a nginx problem.

Same problem for the forum of my website, in antoher VM again, using shoutbox, but here only when I try to authenticate in login page.

0

I think problem is with address in proxy_pass directive. Use there proper hostname insted ip address or add Host header

with defined upstream

upstream agora.mydomain.com {
    server 10.0.2.106;
}

server {
    listen 80;
    server_name     agora.mydomain.com;

    location / {
        proxy_pass      http://agora.mydomain.com;
    }
}

or wtih just Host header

server {
    listen 80;
    server_name     agora.mydomain.com;

    location / {
        proxy_set_header Host $host;
        proxy_pass      http://10.0.2.106;
    }
}
  • Ok that just solved my problem ... I'm really a dick, it was just that! – poka Jul 20 '17 at 13:32
  • Thank you so much. But I don't understand why I don't have the problem on my another server which have exactly the same configuration... Anyway, that's work :) – poka Jul 20 '17 at 13:33

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.