首页 > 解决方案 > PGAdmin 的自定义位置重定向到 'localhost/' nginx

问题描述

我有一个 nginx 服务器,在“localhost/api”上有一个 nodejs API,在“localhost/”上有一个 PGAdmin4。在这种情况下,一切正常,但是一旦我在“localhost/pgadmin4”上的 nginx.conf 中配置 PGAdmin4 的位置,当我单击 PGAdmin4 界面上的登录按钮时,我就会被重定向到“localhost/”因此不要访问 PGAdmin。

我已经尝试了在这里找到的几种解决方案,但没有任何效果..

这是我的 nginx.conf 文件(proxy_pass 中的 pgadmin 在我的 docker-compose.yml 中定义):

user  nginx;
worker_processes auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events { worker_connections 1024; }

http {

  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /dev/null;

  upstream app {
    least_conn;
    server app:3000 weight=10 max_fails=3 fail_timeout=30s;
  }

  sendfile        on;
  #tcp_nopush     on;

  keepalive_timeout  65;

  #gzip  on;

  server {
    listen 80;

    location /api/ {
      proxy_pass http://app;
        proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }

    location /pgadmin {
      proxy_pass http://pgadmin;
        proxy_http_version 1.1;
      proxy_set_header X-Script-Name /pgadmin;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }
  }
}

标签: postgresqlnginxpgadmin

解决方案


使用 apache24 作为反向代理,pgadmin4 与 uWSGI 独立运行,我成功地X-Script-Name在反向代理中设置了标头。

或者,它也可以正常工作,设置X-Script-Name反向代理中的标头,重写反向代理中的 URL 路径组件,而是将以下配置添加到 uWSGI:

route-run               = addvar:SCRIPT_NAME=/pgadmin
route                   = ^/pgadmin(.*) rewrite:$1

这将从中删除重定位 URL 路径组件PATH_INFO并将其放入SCRIPT_NAME,并且与使用的网络服务器无关。

我不熟悉 nginx,但是将您引用的配置与https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html#http-via-nginx上的文档进行比较我可能会假设您的 proxy_path 值是错误的,并且应该包含类似http://localhost:5050/.


推荐阅读