Reputation: 935
Due to some strange project requirements, I am trying to configure Ngnix as a reverse proxy which uses the same hostname that is specified in the incoming request, as the upstream gateway server. The reason this should work is because the public internet DNS will point to our Ngnix server for a given hostname, but the local Ngnix server's resolve.conf will resolve the same hostname to a machine on the local network.
Here is what I have tried:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
location / {
resolver 127.0.0.1;
proxy_pass http://$host;
}
}
}
I am seeing the following in the error log when I attempt to make a request:
*1028 example.test.com could not be resolved (3: Host not found), client: XXX.XXX.XXX.XXX, server: , request: "GET / HTTP/1.1", host: "example.test.com", referrer: "http://foo.com/bar.htm"
When I ping the same hostname from the machine running Ngnix, it is resolved correctly and is reachable.
What am I missing here?
Upvotes: 0
Views: 3468
Reputation: 935
We figured out that the problem had to do with our DNS resolver not supporting ipv6. We disabled ipv6 within the Ngnix config file and it worked. Just had to add "ipv6=off" after the dns resolver address.
Final config file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
location / {
resolver 127.0.0.1 ipv6=off;
proxy_pass http://$host;
}
}
}
Upvotes: 3
Reputation: 1234
you can do it like this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name example.test.com;
location / {
proxy_pass http://192.168.x.x;
}
}
server {
listen 80;
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1;
}
}
}
EDIT
Sorry, I didn't know you need a dynamic configure. But it also need some configure in PROXY SERVER, I think.
Upvotes: -1