nginx後端獲取真實ip

技術小胖子發表於2017-11-17

nginx前端配置

server {

listen 80;

server_name blog.jinchuang.org;

access_log logs/blog.access.log;

error_log logs/blog.error.log;

location / {

proxy_pass http://dis ;
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr; 
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

 

後端nginx配置

server {

listen 80;

server_name blog.jinchuang.org;

access_log logs/blog.access.log;

error_log logs/blog.error.log;

location / {

root html;

index index.php;

}

#獲取真實ip
set_real_ip_from 192.168.0.0/24;  #前端主機的ip段或主機ip
real_ip_header X-Real-IP;
real_ip_header X-Forwarded-For;


location ~ .php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

include fastcgi_params;

}

error_page 404 http://www.jinchuang.org/404.html;

}

      本文轉自無形於有形  51CTO部落格,原文連結:http://blog.51cto.com/jinchuang/1844463,如需轉載請自行聯絡原作者


相關文章