Skip to content

Instantly share code, notes, and snippets.

@rwillians
Created January 30, 2024 16:02
Show Gist options
  • Save rwillians/69e1cdfdec8dd5b5665b16bfdbb526e3 to your computer and use it in GitHub Desktop.
Save rwillians/69e1cdfdec8dd5b5665b16bfdbb526e3 to your computer and use it in GitHub Desktop.
nginx X-Forwarded-For and X-Real-IP
version: '3.9'
services:
nginx:
image: nginx:1.25.3-alpine
depends_on:
- api
ports:
- 3000:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
api:
build: .
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
set_real_ip_from 192.168.65.0/24;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location / {
proxy_pass http://api:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment