phpipam icon indicating copy to clipboard operation
phpipam copied to clipboard

With IPAM_BASE set, login page redirects to / upon login

Open jfstenuit opened this issue 5 years ago • 3 comments

Describe the bug Running in docker container, behind reverse proxy, under specific directory. Upon successful log in, redirects to server root instead of set base directory

phpIPAM version 1.4.1

Your Environment (please supply the following information):

  • phpIPAM version: 1.4.1
  • OS: Alpine Linux 3.10.5
  • PHP version: 7.3.14
  • Webserver: Apache 2.4.43
  • Database: MariaDB 10.4.12

(official docker images phpipam/phpipam-www;latest and mariadb:latest)

Steps To Reproduce

  1. Create docker private bridge:
docker network create ipam-net
  1. Create MariaDB container :
docker run --name mariadb \
        -e MYSQL_ROOT_PASSWORD=... \
        -v /opt/docker/phpipam/mysql:/var/lib/mysql \
        --network ipam-net \
        -d mariadb:latest
  1. Create phpipam container :
docker run --name phpipam \
        -e TZ=Europe/Brussels \
        -e IPAM_BASE=/ipam/ \
        -e IPAM_DATABASE_HOST=mariadb.ipam-net \
        -e IPAM_DATABASE_USER=root \
        -e IPAM_DATABASE_PASS=... \
        --network ipam-net \
        -p 8001:80 \
        -d phpipam/phpipam-www:latest
  1. Configure NGinX reverse proxy :
    location /ipam/ {
        rewrite /ipam/(.*) /$1 break;
        proxy_pass         http://127.0.0.1:8001;
        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $host;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
  1. Log in on the system

Screenshots and error logs N.A.

Additional Info Running behind reverse proxy (see above). When trying to debug using Firefox developer tools (F12 in browser), the symptoms disappear !!! On the other side, the behavior is reproduced systematically when no debugging is taking place in the browser. After being redirected to the root of the webserver (https://webserver/), manually going to the correct URL (https://webserver/ipam/) connects to a logged-in session and work can proceed normally. The abnormal behavior is only triggered on the log-in page.

jfstenuit avatar May 05 '20 12:05 jfstenuit

Hello @jfstenuit

This should be resolved by ee06e67c8cae38eae2a751e34e793c3b730224a7 and X-Forwarded-Uri headers. You'll need to set IPAM_BASE env to /ipam/ in the container.

http {
  server {
    listen       80;
    server_name  nginx-ingress-svr;

    include    /etc/nginx/mime.types;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Uri $uri;

    location /ipam/ {
      proxy_pass http://127.0.0.1:8001;
      proxy_redirect default;
    }
  }
}

GaryAllan avatar Oct 28 '20 22:10 GaryAllan

@GaryAllan - I've had this issue for MONTHS. I had given up my search for a fix, but today I thought I'd have another look and behold, you are the one!

Clarification: adding proxy_set_header X-Forwarded-Uri $uri; fixes this issue when using IPAM_BASE with reverse proxy.

lazynooblet avatar Dec 18 '20 23:12 lazynooblet

Hi. It appears this issue is solved. Can this issue be closed?

riversdev0 avatar Sep 05 '24 00:09 riversdev0