我有以下场景:
服务A
服务 A 在 下可用host:8080
。
我在 nginx 中配置了反向代理来servicea.domain
解析host:8080
.
这是我的配置文件(位置:/etc/nginx/sites-available/servicea)
server {
listen 80;
listen [::]:80;
server_name servicea.domain.com;
location / {
proxy_pass http://host:8080/admin/;
include proxy_params;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 90;
proxy_set_header X-Forwarded-Proto $scheme;
set $xforwardedssl "off";
if ($scheme = https) {
set $xforwardedssl "on";
}
}
}
服务B
我想对服务 B (Grafana)做同样的事情。这可以在 下实现host:3000
。/etc/nginx/sites-available/serviceb下的我的 nginx-config如下所示:
server {
listen 80;
listen [::]:80;
server_name serviceb.domain.com;
location / {
proxy_pass http://host:3000/;
include proxy_params;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 90;
proxy_set_header X-Forwarded-Proto $scheme;
set $xforwardedssl "off";
if ($scheme = https) {
set $xforwardedssl "on";
}
}
}
- 这两个文件都符号链接到/etc/nginx/sites-enabled/。
- Nginx 启动成功并且没有抱怨。
- 调用时一切正常
servicea.domain
。 - 当我打电话时,
serviceb.domain
我在浏览器中收到 400 错误代码。
当我使用 wget 加载页面时,我发现它实际上并未解析为 host:3000 而是解析为 host:80。
╰─$ wget serviceb.domain.com
Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '/home/config/.wget-hsts'. HSTS will be disabled.
--2024-04-08 12:17:00-- http://serviceb.domain.com/
Resolving serviceb.domain.com (serviceb.domain.com)... 10.25.25.34
Connecting to serviceb.domain.com (serviceb.domain.com)|10.25.25.34|:80... connected.
HTTP request sent, awaiting response... 400 Bad Request
2024-04-08 12:17:03 ERROR 400: Bad Request.
这是为什么?我有同样的配置1:1?一点证明配置是相同的。这是 diff 的输出:
╰─$ diff serviceb servicea
5c5
< server_name servicea.domain.com;
---
> server_name serviceb.domain.com;
8c8
< proxy_pass http://host:8080/admin/;
---
> proxy_pass http://host:3000/;
谁能给我一个提示,在哪里可以找到覆盖我的反向代理或以其他方式影响名称解析的设置?如果您需要更多信息,请告诉我。
先感谢您!