771   Nginx

Nginx正向代理,直接贴配置

http{
	resolver 8.8.8.8;
	server {
		listen 80;
		location / {
			proxy_pass http://$http_host$request_uri;
		}
	}

}

主要三个内容
1.添加resolver

2.添加server

3.配置proxy_pass

为了让后端程序获取用户真实的IP,代理需要追加x-forwarded-for的头部信息,如下所示

http{
	resolver 8.8.8.8;
	server {
		listen 80;
		location / {
			proxy_pass http://$http_host$request_uri;
                     
		        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;

		}
	}

}




Leave a Reply

Your email address will not be published. Required fields are marked *