Nginx 代理传递指令:上游错误中的端口无效
Nginx proxy pass directive: Invalid port in upstream error
我正在用 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 which should be encoded by the browser and included as a separate request header according to RFC 7617。
Nginx 不是浏览器,无法为您完成。
您可以将其转换为 Base64 并使用 proxy_set_header
设置 Authorization
header.
例如:
proxy_set_header Authorization "Basic Y2hpcGR1bmstZHVkZTpnb3JnZW91cy1zZXJwZW50cy1jbHViYmVkLW9ycGhhbnM=";
proxy_pass https://nd-657...;
我正在用 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 which should be encoded by the browser and included as a separate request header according to RFC 7617。
Nginx 不是浏览器,无法为您完成。
您可以将其转换为 Base64 并使用 proxy_set_header
设置 Authorization
header.
例如:
proxy_set_header Authorization "Basic Y2hpcGR1bmstZHVkZTpnb3JnZW91cy1zZXJwZW50cy1jbHViYmVkLW9ycGhhbnM=";
proxy_pass https://nd-657...;