设置Nginx反向代理之修改发往上游的请求

在同一个Nginx 的http设置中,添加多一个server{}作为上游服务器:

server {
        listen       8282;
        server_name  localhost;
#服务器返回以下内容
		return 200 '8282 server response.
		uri:$uri
		method:$request_method
		request:$request
		http_name:$http_name
		\n';
		default_type text/plain;
}

在代理服务器中设置发往上游服务器的请求

server {
        listen       8089;
        server_name  localhost;
		default_type text/plain;

        location / {
            root   html;
            index  index.html index.htm;
			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_pass http://localhost:8282;

#以下是设置发往上游服务器的请求的指令			
            proxy_method POST;
			proxy_pass_request_headers on;
			proxy_pass_request_body on;
			proxy_set_body 'hello world!';
			proxy_set_header name '';
			proxy_http_version 1.1;
			proxy_set_header Connection '';
        }
}

测试:

猜你喜欢

转载自blog.csdn.net/aganliang/article/details/87557842