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 #10334DescriptionWhen 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:
- Install Caddy
- 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
- Try to open the domain on web ideally the login page should pop up and the pgadmin4 is accessible
- 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. Activitydev-hari-prasad commented on Aug 20, 2026 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. dev-hari-prasad commented on Aug 20, 2026 Thanks for reporting this, @ranjanport. Before digging further, could you check two things:
-
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.
-
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. ranjanport commented on Aug 20, 2026 I can try to answer this here:
- 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. dev-hari-prasad commented on Aug 21, 2026 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. ranjanport commented on Aug 21, 2026 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. dev-hari-prasad commented on Aug 21, 2026 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. ranjanport commented on Aug 21, 2026 @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? dev-hari-prasad commented on Aug 21, 2026 Paste this webpage into ChatGPT or Claude it should be pretty straightforward. dev-hari-prasad commented on Aug 22, 2026 ranjanport commented on Aug 22, 2026 @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,
- Change the domain name
- Purged all Cloudflare Cache
- Removed Cloudflare DNS Proxy
- 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. dev-hari-prasad commented on Aug 22, 2026 ENHANCED_COOKIE_PROTECTION = False
Pls try this config ranjanport commented on Aug 22, 2026 @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. dev-hari-prasad commented on Aug 22, 2026 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 dpage commented on Aug 25, 2026 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):
- 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;).
- 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. dev-hari-prasad commented on Aug 26, 2026 @ranjanport, did you try the solution mentioned above? This most certainly will fix your problem. Let me know if this fixes it. ranjanport commented on Aug 26, 2026 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
- Created virtual env with
uv
pg/
├── pyproject.toml
├── README.md
├── src
│ └── pg
│ └── __init__.py
└── uv.lock
- 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
- 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
}
}
}rayroutledge commented on Sep 1, 2026 @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
ranjanport commented on Sep 2, 2026 @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. dpage commented on Sep 3, 2026 @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. dpage commented on Oct 13, 2026 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).
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|