Whether the proxy_pass parameter carries a URI
If the proxy_pass parameter carries URI information, the part that matches the location will be replaced with the proxy_pass command setting. E.g:
location /name/ { proxy_pass http://127.0.0.1/remote/; } curl https://example.com/name/example curl http://127.0.0.1/remote/example
If the proxy_pass parameter does not carry URL information, the request will be sent directly to the backend for processing:
location /some/path/ { proxy_pass http://127.0.0.1; } curl https://example.com/name/example curl http://127.0.0.1/name/example
What needs to be distinguished here is the difference between proxy_pass http://127.0.0.1 and proxy_pass http://127.0.0.1/ .
Note:
1) When there are variables in proxy_pass, special processing is required, because the requested URI information cannot be determined at this time.
When does domain name resolution happen
When using the domain name directly...
For the following Nginx configuration information:
server { location / { proxy_pass http://backends.example.com:8080; } }
According to the description of Using the Domain Name in the proxy_pass Directive , the following conclusions can be drawn:
1) When starting or reloading, Nginx will perform DNS resolution and will not resolve it again; if it cannot be resolved, it will return a host not found in upstream error ;
2) Read the /etc/resolv.conf configuration for DNS resolution;
When getting the domain name from the variable...
For the following Nginx configuration information:
resolver 10.0.0.2 valid=10s; server { location / { set $backend_servers backends.example.com; proxy_pass http://$backend_servers:8080; } }
According to the description of Setting the Domain Name in a Variable , the following conclusions can be drawn:
1) After TTL, Nginx will re-resolve the domain name;
2) The resolover parameter must be configured, and valid is used to control the expiration;
3) /etc/resolv will not be used. conf configuration for DNS resolution;