GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unable to run pgadmin4 web version with reverse proxy using Caddy · Issue #10334 · pgadmin-org/pgadmin4

Unable to run pgadmin4 web version with reverse proxy using Caddy #10334

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Unable to run pgadmin4 web version with reverse proxy using Caddy#10334
Copy link
Labels
Bug

Description

@ranjanport
ranjanport
opened on Aug 19, 2026
Issue body actions

When I try to run the web version of pgadmin4 behind the reverse proxy using caddy, the loading spinner comes and revolve continuously. The login page not come and hence unable to use pgadmin4 behind reverse proxy. While the login page is fully functional if I use my IP:PORT/pgadmin4

To Reproduce

Steps to reproduce the behavior:

  1. Install Caddy
  2. Add the config in /etc/caddy/Caddyfile (I have replaced the actual domain)
pgadmin.example.com {
        reverse_proxy 127.0.0.1:5433
}

where I have initialized my pgadmin4 server on 5433

  1. Try to open the domain on web ideally the login page should pop up and the pgadmin4 is accessible
  2. But below error message is shown on console of developer tool. And originally the spinner rotate for too long time and nothing really comes up.

Error message

[Error] Failed to load resource: bad URL (v4513226cdae34746b4dedf0b4dfa099e1781791509496, line 0)
[Error] Refused to execute https://pgadmin.example.com/pgadmin4/static/vendor/require/require.min.js?ver=91700 as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.
[Error] ReferenceError: Can't find variable: require
	Global Code (login:54)
[Log] ReferenceError: Can't find variable: require — login:113 (login, line 123)
[Warning] Source Map "https://pgadmin.example.com/pgadmin4/static/js/generated/pgadmin_commons.js.map" has SyntaxError: JSON Parse error: Unrecognized token '<'

** Environment**

  • OS: Linux
  • pgAdmin version: latest
  • Mode: [Server]
  • Browser (if running in server mode): [chrome, safari]
  • Package type: [DEB, Python, Container] attempted tests using these might impact other package type too.

Additional context
It is better if there should be a document section under deployment using reverse proxy using Caddy this will help most of the user running Caddy for there deployment.

Activity

  1. ranjanport
    added
    Bug
    on Aug 19, 2026
  2. dev-hari-prasad commented on Aug 20, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 20, 2026
    Contributor
    More actions

    I'm looking into this and will try to reproduce the issue on my VPS. I'll share an update once I have a better understanding of what's causing it.

  3. dev-hari-prasad commented on Aug 20, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 20, 2026
    Contributor
    More actions

    Thanks for reporting this, @ranjanport. Before digging further, could you check two things:

    1. Network tab:
      Open DevTools → Network → reload the page → find the request for require.min.js → check its status code, actual Content-Type response header, and the response body (does it start with <!DOCTYPE html>?). This will confirm whether the proxy is returning an HTML error/redirect page instead of the actual JS file.

    2. pgAdmin4 subpath config:
      Are you running pgAdmin4 with SCRIPT_NAME=/pgadmin4 (or similar) so it expects to be served under a subpath? Your Caddyfile doesn't do any path rewriting (reverse_proxy 127.0.0.1:5433 proxies everything as-is), so if pgAdmin4 itself is expecting a subpath prefix that Caddy isn't telling it about, that mismatch could be the cause.

    I have not yet reproduced this on VPS or locally. Before I do that, pls do supply me with this information so I can better understand the problem at hand so, we can fix and diagnose this further.

  4. ranjanport commented on Aug 20, 2026

    @ranjanport
    ranjanport
    on Aug 20, 2026
    Author
    More actions

    I can try to answer this here:

    1. I can't see any Request/Response metadata in require.min.js i.e;
    Summary
    URL: https://pgadmin.nxpanel.tech/pgadmin4/static/vendor/require/require.min.js?ver=91700
    Status: —
    Source: —
    
    Request
    No request headers
    
    Response
    No response headers
    
    Query String Parameters
    ver: 91700
    
    

    @dev-hari-prasad You can check this as the service is currently hosted at https://pgadmin.nxpanel.tech/pgadmin4.

    In the meanwhile I have already tried to put the SCRIPT_NAME=/pgadmin4 flag under caddy but got no success.

  5. dev-hari-prasad commented on Aug 21, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 21, 2026
    Contributor
    More actions

    I will have to do some digging; I will let you know once I have something useful. By the looks of it seems like this is a pgAdmin bug, but I can't vouch for it unless I do a more thorough investigation into this.

  6. ranjanport commented on Aug 21, 2026

    @ranjanport
    ranjanport
    on Aug 21, 2026
    Author
    More actions

    Sure, @dev-hari-prasad have a look into this, our team members asked for this as everyone needed a centralized globally accessible solution for db management. But due to security regions I can only expose this behind the proxy and while doing so this happen.

    If you are able to replicate and fix this do let me know of the solution which I can also implement at my end.

  7. dev-hari-prasad commented on Aug 21, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 21, 2026
    Contributor
    More actions

    require.js fetches an auth-gated dynamic route (browser/js/utils.js), the session cookie isn't sent because it's missing the Secure flag on the HTTPS-proxied connection, so it 302s to /login, and the browser refuses to execute the returned HTML as a script.

    Try setting SESSION_COOKIE_SECURE = True in config_local.py. That alone should fix it, since it is the missing piece that was breaking the session cookie over HTTPS. Also set PROXY_X_HOST_COUNT = 1 and PROXY_X_PREFIX_COUNT = 1 so pgAdmin will trust the Caddy-forwarded requests.

    Ofc, make sure Caddy is configured correctly, especially do NOT strip the /pgadmin4 prefix in Caddy since SCRIPT_NAME=/pgadmin4 and the handle /pgadmin4/* must match. and restart the container/system to make sure these changes are applied.

    Let me know if that fixes it for you.

  8. ranjanport commented on Aug 21, 2026

    @ranjanport
    ranjanport
    on Aug 21, 2026
    Author
    More actions

    @dev-hari-prasad I can give it a try could you let me know where exactly I should modify these if I have installed it using apt. Can you provide me a final proxy config and the location where the config_local.py exists. Is it a bug or something which needed to be integrated in coming days?

  9. dev-hari-prasad commented on Aug 21, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 21, 2026
    Contributor
    More actions

    Paste this webpage into ChatGPT or Claude it should be pretty straightforward.

  10. dev-hari-prasad commented on Aug 22, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 22, 2026
    Contributor
    More actions

    @ranjanport Did that fix it for you?

  11. ranjanport commented on Aug 22, 2026

    @ranjanport
    ranjanport
    on Aug 22, 2026
    Author
    More actions

    @dev-hari-prasad I have tried and here is the config I am currently using

    pgadmin.mynx.dpdns.org {
        reverse_proxy 127.0.0.1:5050
    }

    Also, tried with

    pgadmin.mynx.dpdns.org {
        reverse_proxy pgadmin4/* 127.0.0.1:5050
    }

    Putting headers too

    pgadmin.nxpanel.tech {
        reverse_proxy /pgadmin4/* 127.0.0.1:5050 {
            header_up X-Forwarded-Prefix /pgadmin4
            header_up X-Forwarded-Proto https
        }
    }

    Added below to config_local.py located in my virtual env at /opt/pgAdminServer/.venv/lib/python3.12/site-packages/pgadmin4/config_local.py

    PROXY_X_FOR_COUNT = 1
    PROXY_X_PROTO_COUNT = 1
    PROXY_X_HOST_COUNT = 1
    PROXY_X_PORT_COUNT = 1
    PROXY_X_PREFIX_COUNT = 1
    SESSION_COOKIE_SECURE = True
    

    Also, checked internally that all the responses are 200 for

    curl -sI http://127.0.0.1:5050/static/vendor/require/require.min.js
    curl -sI https://pgadmin.mynx.dpdns.org/static/vendor/require/require.min.js
    curl -s https://pgadmin.mynx.dpdns.org/static/vendor/require/require.min.js | head -c 200
    curl -sI http://127.0.0.1:5433/pgadmin4/static/js/generated/security.pages.js
    curl -sI https://pgadmin.nxpanel.tech/pgadmin4/static/js/generated/security.pages.js
    curl -sI http://127.0.0.1:5433/pgadmin4/static/js/generated/security.pages.js.map
    curl -s https://pgadmin.nxpanel.tech/pgadmin4/login?next=/pgadmin4/browser/ | grep -i "security.pages\|require.config\|baseUrl"
    curl -s http://127.0.0.1:5433/pgadmin4/login?next=/pgadmin4/browser/ | grep -i "security.pages\|require.config\|baseUrl"
    

    Also,

    1. Change the domain name
    2. Purged all Cloudflare Cache
    3. Removed Cloudflare DNS Proxy
    4. Switch from CNAME to A record.

    The outcome is I am able to get the login page but post login button click the page got refresh and put me back to the login page.

    I think you need to put a documentation on Running pgadmin4 behind the reverse proxy using caddy and cloudflare.

  12. dev-hari-prasad commented on Aug 22, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 22, 2026
    Contributor
    More actions

    ENHANCED_COOKIE_PROTECTION = False

    Pls try this config

  13. ranjanport commented on Aug 22, 2026

    @ranjanport
    ranjanport
    on Aug 22, 2026
    Author
    More actions

    @dev-hari-prasad Tried with this flag but it is Not working, I must say that the team should add a documentation on how to correctly runpgadmin4 using caddy.

  14. dev-hari-prasad commented on Aug 22, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 22, 2026
    Contributor
    More actions

    Could you check whether the session cookie is being set after clicking Login, and whether the same cookie is sent with the subsequent request to /browser/?

    As for the documentation part, I'm not very familiar with the current deployment documentation, so I can't really say whether anything is missing there. It might be worth having someone more familiar with that area take a look and see if there's anything that could be clarified around running pgAdmin behind Caddy/reverse proxies.

    @asheshv @khushboovashi

  15. dpage commented on Aug 25, 2026

    @dpage
    dpage
    on Aug 25, 2026
    Contributor
    More actions

    I've reproduced this locally and tracked down the actual cause, which turns out to be different from the cookie/ENHANCED_COOKIE_PROTECTION theories discussed above.

    Two separate things need to line up for a sub-directory deployment (/pgadmin4):

    1. The proxy must forward the request path unmodified (don't strip the /pgadmin4 prefix) and tell pgAdmin about the prefix with the X-Script-Name header — this is what the existing NGINX docs already do (proxy_set_header X-Script-Name /pgadmin4;).
    2. pgAdmin's own process needs a SCRIPT_NAME environment variable set at startup. This is a separate, static mechanism (evaluate_config.py) from the per-request X-Script-Name header above: it's what sets APPLICATION_ROOT and SESSION_COOKIE_PATH. Without it, Flask-Security's post-login redirect goes to bare / instead of /pgadmin4, which lands outside the proxied path — this is almost certainly what caused "I get the login page but after clicking Login it just goes back to the login page".

    There's also a Caddy-specific gotcha: a path /pgadmin4/* matcher does not match the bare /pgadmin4 (no trailing slash) that pgAdmin redirects to after login — Caddy will silently return an empty 200 instead of proxying it. The matcher needs to include both /pgadmin4 and /pgadmin4/*.

    A working Caddyfile for a sub-directory deployment:

    pgadmin.example.com {
    	@pgadmin path /pgadmin4 /pgadmin4/*
    	handle @pgadmin {
    		reverse_proxy 127.0.0.1:5433 {
    			header_up X-Script-Name /pgadmin4
    		}
    	}
    }
    

    ...plus SCRIPT_NAME=/pgadmin4 in the environment of the process that runs pgAdmin itself (e.g. a systemd Environment= line, or passed to gunicorn/uwsgi if you're running under one of those).

    I verified this end-to-end locally: ran pgAdmin under /pgadmin4 behind Caddy, and drove a real browser through login → dashboard → full page reload with no console errors and no redirect loop. SESSION_COOKIE_SECURE/ENHANCED_COOKIE_PROTECTION weren't needed for the plain sub-directory case above; they may still matter for setups with an additional layer (e.g. Cloudflare) in front, but aren't the root cause here.

    I'll be opening a documentation PR adding Caddy examples (mirroring the existing NGINX ones, for both Gunicorn and uWSGI) so this is easier to get right in future.

    Reacted by Hari Prasad
  16. dev-hari-prasad commented on Aug 26, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Aug 26, 2026
    Contributor
    More actions

    @ranjanport, did you try the solution mentioned above? This most certainly will fix your problem. Let me know if this fixes it.

  17. ranjanport commented on Aug 26, 2026

    @ranjanport
    ranjanport
    on Aug 26, 2026
    Author
    More actions

    I tried the exact mentioned steps @dev-hari-prasad
    @dpage I just replicated the steps you mentioned in the documentation but login page redirection is still not working as expected and the page refresh back to Login.

    To better answer your question I have added the deployment here https://pg.mynx.dpdns.org/login?next=/ using gunicorn --bind 127.0.0.1:5050 --workers=1 --threads=25 --chdir .venv/lib/python3.13/site-packages/pgadmin4/ pgAdmin4:app

    pg.mynx.dpdns.org {
            reverse_proxy 127.0.0.1:5050
    }

    Also, tried with socket method originally mentioned but no luck. Does Cloudflare make any issue here cause I only have A records with no dns proxy on cloudflare

    Tried both the gunicorn and uwsgi deployment with these commands

    1. Created virtual env with uv
    pg/
    ├── pyproject.toml
    ├── README.md
    ├── src
    │   └── pg
    │       └── __init__.py
    └── uv.lock
    
    1. Ran uv add pgadmin4 gunicorn uwsgi and then while on root dir i.e; pg started the server
    SCRIPT_NAME=/pgadmin4 uwsgi --http-socket /tmp/pgadmin4.sock --processes 1 --threads 25 --chdir .venv/lib/python3.13/site-packages/pgadmin4/ --manage-script-name --mount /pgadmin4=pgAdmin4:app
    1. Added proxy config to caddy
    pg.mynx.dpdns.org {
            @pgadmin path /pgadmin4 /pgadmin4/*
            handle @pgadmin {
                    reverse_proxy unix//tmp/pgadmin4.sock {
                    header_up X-Script-Name /pgadmin4
                    }
            }
    }
  18. rayroutledge commented on Sep 1, 2026

    @rayroutledge
    rayroutledge
    on Sep 1, 2026
    More actions

    @ranjanport i was having the same issue, i have these settings and its now working.

    NginX

        location = /PGAdmin {
            return 301 /PGAdmin/;
        }
    
        location /PGAdmin/ {
            proxy_pass http://127.0.0.1:5050/;
            proxy_set_header Host $host;
            proxy_set_header X-Script-Name /PGAdmin;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_redirect off;
            proxy_buffering off;
            proxy_read_timeout 300s;
            proxy_connect_timeout 60s;
            proxy_send_timeout 300s;
        }
    

    Docker compose

          PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: "False"
          PGADMIN_CONFIG_SESSION_COOKIE_SECURE: "True"
          PGADMIN_CONFIG_SESSION_COOKIE_HTTPONLY: "True"
          PGADMIN_CONFIG_SESSION_COOKIE_SAMESITE: "'Lax'"
          PGADMIN_CONFIG_PROXY_X_FOR_COUNT: 1
          PGADMIN_CONFIG_PROXY_X_PROTO_COUNT: 1
          PGADMIN_CONFIG_PROXY_X_HOST_COUNT: 1
    
  19. ranjanport commented on Sep 2, 2026

    @ranjanport
    ranjanport
    on Sep 2, 2026
    Author
    More actions

    @rayroutledge My problem is explicit to caddy with nginx it is working fine. But as my server already have a lot of configuration done via caddy so I don't want to change it and wanted to run within.

  20. dpage commented on Sep 3, 2026

    @dpage
    dpage
    on Sep 3, 2026
    Contributor
    More actions

    @ranjanport Your deployment isn't currently reaching pgAdmin at all: /pgadmin4 and /pgadmin4/login both return 502, and everything else returns an empty 200, which is what Caddy sends for a path matching no handler. Three things, in order:

    • The 502 is the socket. If Caddy runs as a systemd service, its packaged unit sets PrivateTmp=true, so /tmp/pgadmin4.sock isn't the same file for Caddy as it is for uWSGI. Move it somewhere both can reach, such as /run/pgadmin4/pgadmin4.sock, or bind uWSGI to 127.0.0.1:5050 and proxy to that instead.
    • Then try ENHANCED_COOKIE_PROTECTION = False in config_local.py. It is enabled by default and binds the session to a hash of the User-Agent and the first X-Forwarded-For entry, read straight from the header (it does not use PROXY_X_FOR_COUNT). If that value differs between two requests the session is discarded and you are sent back to the login page, which is your symptom exactly. Your earlier test of this flag was against a deployment that we now know wasn't proxying correctly anyway.
    • If that turns out to be it, suspect HTTP/3. Caddy serves it by default (your server advertises alt-svc: h3=":443") whilst NGINX does not, and a browser moving from TCP to QUIC mid-session can present a different public address behind CGNAT or a dual-stack connection, which changes that first X-Forwarded-For entry. Rule it out with servers { protocols h1 h2 } in the global block.

    I re-tested both configurations from my earlier comment with your exact Gunicorn and uWSGI command lines, over HTTPS through Caddy, and both log in and load the dashboard normally, so I can't reproduce the loop itself here.

    One correction to that comment: SCRIPT_NAME is worth setting, but it isn't the cause of the login bounce on its own. Without it the normal flow still works, because /pgadmin4/ redirects to /pgadmin4/login?next=/pgadmin4/ and the prefix rides along in next; it only goes wrong if you open the login page directly with no next, and it scopes the session cookie to / rather than /pgadmin4.

    Caddy examples for both Gunicorn and uWSGI are in #10344.

  21. dpage
    added a commit that references this issue on Sep 14, 2026

    docs: address review of the Caddy reverse proxy examples

    9071ba8
  22. dpage
    added a commit that references this issue on Sep 22, 2026

    Add Caddy reverse proxy configuration examples (#10344)

    2ba68de
  23. dpage commented on Oct 13, 2026

    @dpage
    dpage
    on Oct 13, 2026
    Contributor
    More actions

    Closing this as I couldn't reproduce the login loop with either the Gunicorn or uWSGI configuration through Caddy, and there's been no update for over a month. The working Caddy examples are in #10344; if you still see the problem with one of those, please reopen with the Caddyfile and server command line you're using, plus the browser network trace for the login request (with any cookies or tokens redacted).

  24. dpage
    closed this as not plannedon Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.