https://github.com/lyokha/nginx-proxy-peer-host
Variable $proxy_peer_host
https://github.com/lyokha/nginx-proxy-peer-host
nginx proxy proxy-peer-host proxy-ssl-name upstream
Last synced: about 2 months ago
JSON representation
Variable $proxy_peer_host
- Host: GitHub
- URL: https://github.com/lyokha/nginx-proxy-peer-host
- Owner: lyokha
- License: other
- Created: 2024-08-15T18:22:22.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-15T16:39:14.000Z (about 1 year ago)
- Last Synced: 2025-04-15T17:40:51.460Z (about 1 year ago)
- Topics: nginx, proxy, proxy-peer-host, proxy-ssl-name, upstream
- Language: C
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
nginx-proxy-peer-host
=====================
[](https://github.com/lyokha/nginx-proxy-peer-host/actions?query=workflow%3ACI)
This Nginx HTTP module provides only one variable *$proxy_peer_host*
which is similar to variable *$proxy_host* from [Nginx HTTP proxy
module](https://nginx.org/en/docs/http/ngx_http_proxy_module.html). While the
latter variable contains the name of the upstream which a client request is
being proxied to, variable *$proxy_peer_host* contains the name of the
actual server inside the upstream given it was configured in directive
*upstream*.
Let's test a simple configuration.
```nginx
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
upstream u1 {
server 127.0.0.1:8080;
server localhost:8080;
}
server {
listen 8010;
server_name main;
location /u1 {
proxy_pass http://u1;
echo_after_body "[u1] proxy_peer_host: $proxy_peer_host";
echo_after_body " proxy_host: $proxy_host";
}
}
server {
listen 8080;
server_name backend;
location / {
return 200;
}
}
}
```
The value of *$proxy_peer_host* must rotate in a round-robin manner when
we do sequential HTTP requests to location */u1*.
```ShellSession
$ curl 'http://localhost:8010/u1'
[u1] proxy_peer_host: 127.0.0.1:8080
proxy_host: u1
$ curl 'http://localhost:8010/u1'
[u1] proxy_peer_host: localhost:8080
proxy_host: u1
$ curl 'http://localhost:8010/u1'
[u1] proxy_peer_host: localhost:8080
proxy_host: u1
$ curl 'http://localhost:8010/u1'
[u1] proxy_peer_host: 127.0.0.1:8080
proxy_host: u1
```
Variable *$proxy_peer_host* can be used in directive *proxy_ssl_name* to
verify names of backend servers against the names given in directives *server*
inside the upstream rather than the name of the upstream itself.