Setup
I have three virtual hosts: host.test
is proxy_passing all requests to backend. Backend is available from WAN via some domain name (backend-domain.net
).
There is also a fallback (default_server on port 80).
Configuration
server {
listen 80;
server_name host.test;
location /_/ {
proxy_pass http://127.0.0.1:80/;
proxy_set_header Host "backend-domain.net";
}
}
server {
listen 80;
server_name backend-domain.net;
access_log /var/log/backend-domain.net.log;
root /var/www/html;
}
server {
listen 80 default_server;
access_log /var/log/default-server.log;
}
Problem
I'd like to get rid of the DNS resolver and use just the IP + Host header. (I know that I can use a local DNS resolver, but I'd like to keep things simple).
For some reason I cannot proxy_pass using the local address 127.0.0.1
. What I've tried:
- [doesn't work] proxy_pass to 127.0.0.1 and set
Host
header
- [doesn't work] proxy_pass to 127.0.0.1:80 and set
Host
header
- [doesn't work] proxy_pass to
localhost
and set Host
header
- [doesn't work] all of above + changing
proxy_http_version
- [works] proxy_pass to
http://backend-domain.net
All requests made to host.test
are displayed in fallback host's logs. It shows valid host
:
# /var/log/default-server.log:
2021/01/05 20:43:46 [error] 17860#17860: blah-blah, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", host: "backend-domain.net"
Question
Why are requests being processed by default_server
even though the correct Host
header is set? How do I make my setup work?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…