I have the following scenario:
Service A
Service A is available under host:8080
.
I have configured a reverse proxy in nginx to resolve servicea.domain
to host:8080
.
Here is my config-file (Location: /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";
}
}
}
Service B
I would like to do the same with Service B (Grafana). This can be reached under host:3000
.
My nginx-config under /etc/nginx/sites-available/serviceb looks like this:
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";
}
}
}
- Both files are symlinked to /etc/nginx/sites-enabled/.
- Nginx starts successfully and does not complain.
- Everything works when calling
servicea.domain
. - Ehen calling
serviceb.domain
I get a 400 error code in the browser.
When I use wget to load the page, I see that it does not actually resolve to host:3000 but to 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.
Why is that? I have the same configuration 1:1? A little proof that the config is the same. Here is the output of 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/;
Can anyone give me a hint where I can find settings that override my reverse proxy or otherwise impact name resolution? Let me know, if you need further information.
Thank you in advance!
listen 80;
,listen [::]:80;
, Reverse-Proxy for service A is listen to port 80. Same for service B.host:port
, but also underservice-xy.domain.com
. To do this, I have set up a reverse proxy with nginx using the configuration mentioned above. My problem is, that I can reach some services, but for other services where for example only the port or the host is different, I cannot reach them.