1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| [root@proxy ~] server { listen 80; server_name forward.linuxds.com; access_log /var/log/nginx/forward.access.log main; error_log /var/log/nginx/forward.error.log warn; location / { proxy_pass https: proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } 1 [root@proxy ~] 2 [root@proxy ~]
|
配置释义
proxy_set_header X-Real-IP $remote_addr:把源IP【$remote_addr,建立HTTP连接header里面的信息】赋值给X-Real-IP,从而通过$X-Real-IP来获取源IP;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for:在nginx作为代理服务器时,设置的IP列表,会把经过的机器ip,代理机器ip都记录下来,用【,】隔开。
配置案例
说明:服务器A想请求苹果的接口,但不想直接通过服务器A去请求,想通过服务器B去代理请求,同时要求伪装ip,配置如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| server { listen 80; server_name proxygrow.nineton.cn;
location /adservices { proxy_pass https: proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
|