【问题标题】:Custom location for PGAdmin redirect to 'localhost/' nginxPGAdmin 的自定义位置重定向到 'localhost/' nginx
【发布时间】:2020-05-24 12:04:21
【问题描述】:

我有一个 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;
    }
  }
}

【问题讨论】:

    标签: postgresql nginx pgadmin


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • proxy_path 看起来不错,因为“pgadmin”是我的 docker-compose.yml 中定义的主机名。如果我输入localhost:5050,我得到相同的结果,如果我输入pgadmin
    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    • 2019-06-16
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多