在docker中运行pgadmin4时CSRF令牌错误请求

时间:2020-09-16 11:48:53

标签: postgresql docker flask pgadmin

我正在尝试在反向代理后面的docker容器中运行pgadmin4。 PgAdmin4正在连接到远程数据库。我遇到的问题是我不断收到以下错误:


flask_wtf.csrf.CSRFError: 400 Bad Request: The CSRF token is invalid.

pgadmin_1  | Traceback (most recent call last):
pgadmin_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1811, in full_dispatch_request
pgadmin_1  |     rv = self.preprocess_request()
pgadmin_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2087, in preprocess_request
pgadmin_1  |     rv = func()
pgadmin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 224, in csrf_protect
pgadmin_1  |     self.protect()
pgadmin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 259, in protect
pgadmin_1  |     self._error_response(e.args[0])
pgadmin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 302, in _error_response
pgadmin_1  |     raise CSRFError(reason)
pgadmin_1  | flask_wtf.csrf.CSRFError: 400 Bad Request: The CSRF token is invalid.

以下是我的撰写文件:

version: "3.3"
services:
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: email@domain.com
      PGADMIN_DEFAULT_PASSWORD: PassPass
      PGADMIN_LISTEN_PORT: 5050
      #SCRIPT_NAME: /pgadmin4
      PGADMIN_LISTEN_ADDRESS: 0.0.0.0
    ports:
    - "5050:5050"
    network_mode: "host"
    volumes:
    - pgadmin:/var/lib/pgadmin

volumes:
  pgadmin:

和反向代理

# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;
}

# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name servername;

    # Use the Let’s Encrypt certificates
    # ssl conf


    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:8081/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }

    location /pgadmin4 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Script-Name /pgadmin4;
        proxy_set_header Host $host;
        proxy_pass http://localhost:5050/;
        proxy_redirect off;
    }



}

我不知道错误的根源是通过以下指南https://www.pgadmin.org/docs/pgadmin4/development/container_deployment.html

但是我不确定是什么原因造成的

0 个答案:

没有答案
相关问题