Project

General

Profile

Feature #673

Display Real IP Address To Nginx Backend

Added by Daniel Curtis about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Server
Target version:
Start date:
10/09/2015
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

I use nginx as both a reverse proxy and a web server, each their own server. While examining the log files I found that incoming requests to the backend web server were showing that they were coming from the proxy servers IP address and not from the actual clients IP address.

Proxy Server Frontend

  • To start edit the proxy config:
    vi /usr/local/etc/nginx/proxy.d/www.example.com.conf
    
    • And add the following to the server block:
      proxy_set_header    Host            $host;
      proxy_set_header    X-Real-IP       $remote_addr;
      proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
      
  • Then restart nginx:
    service nginx restart
    

Web Server Backend

  • Recompile nginx with the real IP module:
    cd /usr/ports/www/nginx
    make config
    make reinstall clean
    
    • Make sure to enable [X]REALIP when configuring nginx
  • On the web server backend, edit the server config:
    vi /usr/local/etc/nginx/conf.d/www.example.com
    
    • And add the following to the server block:
      set_real_ip_from  192.168.100.55; #Upstream proxy server address
      real_ip_header    X-Forwarded-For;
      

Resources

History

#1 Updated by Daniel Curtis about 5 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

#2 Updated by Daniel Curtis about 5 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF