我有一个nginx服务器,在 "localhostapi "上有nodejs API,在 "localhost "上有PGAdmin4。在这种情况下,所有的工作都没有问题,但是当我在'localhostpgadmin4'的nginx.conf中配置PGAdmin4的位置时,当我点击PGAdmin4界面上的登录按钮时,我被重定向到'localhost',因此无法访问PGAdmin。
我已经尝试了几个解决方案,但没有任何效果。
这是我的nginx.conf文件(pgadmin在proxy_pass中的定义是在我的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;
}
}
}
使用apache24作为反向代理,pgadmin4使用uWSGI独立运行,我成功地设置好了 X-Script-Name
的头。
或者,它也可以在 不 设置 X-Script-Name
头的反向代理。不 在反向代理中重写URL路径组件,但...。而是 为uWSGI添加以下配置。
route-run = addvar:SCRIPT_NAME=/pgadmin
route = ^/pgadmin(.*) rewrite:$1
这将从 PATH_INFO
并将其放入 SCRIPT_NAME
而且与使用的webserver无关。
我对nginx不熟悉,但比较你引用的配置和文档,在 https:/www.pgadmin.orgdocspgadmin4latestcontainer_deployment.html#http-via-nginx 我可能认为你的proxy_path值是错误的,应该包含如下内容 http://localhost:5050/
.