Nginx代理传递指令:上游错误中的端口无效



我正在使用Nginx进行负载平衡。这是我的配置

upstream web_backend {
least_conn;
server localhost:8001  max_fails=3 fail_timeout=60s;
server localhost:8002  max_fails=3 fail_timeout=60s;
}

server {
listen 8545;
server_name _;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_backend;
}
}

server {
listen 8001;
server_name localhost;
location / {
proxy_pass https://some_other_url/v3/cxnmcdinwrtyf93vcwdiyfx8q6xqwxv9qg7c93fgcb;
}
}
server {
listen 8002;
server_name localhost;
location / {
proxy_pass 'https://chipdunk-dude:gorgeous-serpents-clubbed-orphans@nd-657-555-555-777.dogify.com';
}
}

正如你所看到的,8002端口的url很奇怪(甚至不知道这种url叫什么(因为它具有":"在url中,Nginx给了我这个错误

nginx: [emerg] invalid port in upstream "chipdunk-dude:gorgeous-serpents-clubbed-orphans@nd-657-555-555-777.dogify.com" in /etc/nginx/sites-enabled/default:60

8001端口的url运行良好。

@之前的所有内容都是userinfo,应该由浏览器编码,并根据RFC 7617作为单独的请求标头包含。

Nginx不是一个浏览器,不能为你做这件事。

您可能可以将其转换为Base64,并使用proxy_set_header设置Authorization标头。

例如:

proxy_set_header Authorization "Basic Y2hpcGR1bmstZHVkZTpnb3JnZW91cy1zZXJwZW50cy1jbHViYmVkLW9ycGhhbnM=";
proxy_pass https://nd-657...;

最新更新