我遇到了一些麻烦:pgadmin在location /中的Nginx后面工作得很好,但是在后面/ pgadmin的地方不能工作
工作出色:
location / {
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:5050;
}
无效的工作:
location /pgadmin {
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:5050;
}
可能我需要一些特定的重写吗?
最佳答案
对于版本pgAdmin 4 v3.0,在实际解决该问题之前,这是基于this的快速命令行黑客.
cat > quickfix.txt <<THE_END
class ReverseProxied(object):
def __init__(self,app):
self.app = app
def __call__(self,environ,start_response):
script_name = environ.get("HTTP_X_SCRIPT_NAME","")
if script_name:
environ["SCRIPT_NAME"] = script_name
path_info = environ["PATH_INFO"]
if path_info.startswith(script_name):
environ["PATH_INFO"] = path_info[len(script_name):]
scheme = environ.get("HTTP_X_SCHEME","")
if scheme:
environ["wsgi.url_scheme"] = scheme
return self.app(environ,start_response)
app.wsgi_app = ReverseProxied(app.wsgi_app)
THE_END
sudo sed -i '/app = create_app()/r quickfix.txt' /usr/local/lib/python3.5/dist-packages/pgadmin4/pgAdmin4.py
rm quickfix.txt
上面的命令在app = create_app()行之后,将一段代码插入文件/usr/local/lib/python3.5/dist-packages/pgadmin4/pgAdmin4.py中.
另外,请确保系统上pgAdmin4.py的路径正确.您可能需要调整上面的代码段.
然后,如下配置Nginx:
location /pgadmin-web/ {
proxy_pass http://127.0.0.1:5050/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Script-Name /pgadmin-web;
}
作为参考,还可以在GitHub上查看pgAdmin4.py.