go_clientinfo/_extras/nginx.conf
2024-12-12 02:22:54 -05:00

75 lines
2.3 KiB
Nginx Configuration File

worker_processes 1;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
server {
listen [::]:80 ipv6only=off default_server;
server_name localhost _;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/debug.log debug;
error_log /var/log/nginx/error.log;
# You MUST set this for dual-stack setups!
set $client_ip_port "$remote_addr:$remote_port";
if ($remote_addr ~ "^.+:.+$") {
set $client_ip_port "[$remote_addr]:$remote_port";
}
location / {
# For UDS FastCGI (the default URI).
# UDS FastCGI is the recommended setup, as it provides the most accuracy,
# requires the least amount of configuration, and is the most performant.
# Yes, Virginia, even more performant than localhost network ports.
include fastcgi.inc;
fastcgi_pass unix:/var/run/clientinfo/fcgi.sock;
#
# For TCP FastCGI. (See the clientinfo.env file for a corresponding URI.)
#include fastcgi.inc;
#fastcgi_pass 127.0.0.1:4321;
#
# For HTTP. (See the clientinfo.env file for a corresponding URI.)
# BE SURE to explicitly set (NOT add) the X-ClientInfo-RealIP header
# if reverse-proxying, and enclose in brackets if IPv6!
# (FastCGI via fastcgi.inc does this automatically for fastcgi_pass.)
# Note that in dual-stack NGINX (as configured here), the $client_ip_port
# will use IPv6-mapped IPv4 (https://www.rfc-editor.org/rfc/rfc5156.html#section-2.2)
# for IPv4 clients, which looks like e.g. "[::ffff:<IP>]:<Port>".
# FastCGI will use the expected "<IP>:<Port>" format for IPv4 clients.
#proxy_set_header X-ClientInfo-RealIP "$client_ip_port";
#proxy_http_version 1.1;
#proxy_pass http://127.0.0.1:1234;
}
# Alternatively, if you only wanted to return the client's IP,
# you don't even need ClientInfo, it can be returned directly.
# See https://nginx.org/en/docs/varindex.html
location /ip {
return 200 "$remote_addr";
}
# Likewise, ...
location /ipport {
return 200 "$client_ip_port";
}
# And so forth.
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}