Today, when configuring a location, you want to use a variable such as $ host to indicate the nginx Proxy: locationtest {proxy_passhttp: $ host;}. If you do not think of it, this configuration cannot be used, view error. log, and the output information cannot help solve the problem. But in the same case, the root tag works well: loca
Configuring a lo todayCatIon, you want to use a variable such as $ host to indicate the nginx Proxy:
Location/test /{
Proxy_pass http: // $ host;
}
If you don't think of it, this configuration cannot be used. You can view error. log and the output information cannot help solve the problem.
But in the same case, the root tag works well:
Locatin/test /{
Root/dev/shm/$ host;
}
What is incredible. Is it estimated that this is a bug of nginx or an ambiguous logic?
Change the above error configuration
Location/test /{
Proxy_pass http: // $ host /;
}
Or
Set$ Vhost test.SuDone.com;
Location/test /{
Proxy_pass http: // $ vhost;
}
The problem cannot be solved. In the end, a strange configuration method is used to work ......
Location/test /{
Proxy_pass http: // 127.0.0.1: 80;
Proxy_set_header Host $ host;
}
This configuration can work normally, but the above configuration only supports the backend of A Single ip address, can it support ups?TrWhat about eam?
Change the test
Upstream backend.sudone.com {
Server 127.0.0.1: 80;
}
Location/test /{
Proxy_pass http://backend.sudone.com; # fixed write back-end upstream
Proxy_set_header Host $ host; # $ host = test.sudone.com;
}
Hmm? Usable!
With this method, I do not need to mount the/test/location dozens of times in dozens of host configurations. In addition, it supports the following syntax:
Location/test /{
Proxy_pass http: // 127.0.0.1: 80;
Proxy_set_header Host fetch. $ host;
}
You can also useRegular ExpressionThe expression matches the host:
Set $ vhost $ host;
If $ host ~ * ([^.] +) .Sudone.com {
Set $ vhost $ 1.xxx.com;
}
Location/test /{
Proxy_pass http: // 127.0.0.1: 80;
Proxy_set_header Host fetch. $ host;
}
Wide Range of availability.
---------------------------------------------------
Supplement:
In this configuration, the backend of my nginx proxy is also nginx. It is not clear whether other web servers, such as apache, can work normally under this configuration.