from:http://blog.csdn.net/luckykapok918/article/details/44461465
Nginx through 80-port reverse proxy to Tomcat implementation is very simple, through the JSP Request.getserverport () get to the port number is still 80, And if nginx using a non-80 port to do the Echo Agent Request.getserverport () get to the port number returned will still be 80, so the edge is not correct response.sendredirect
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
So Response.sendredirect will jump to port 80.
Solution:
Modify proxy.conf Get you write the agent's configuration into the Nginx, or you can modify it internally
Proxy_redirect off;
# nginx Non 80 port processing
Proxy_set_header Host $host: $server _port;
# Get real IP
Proxy_set_header X-real-ip $remote _addr;
# Get the real IP of the agent
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Client_max_body_size 10m;
Client_body_buffer_size 128k;
Proxy_connect_timeout 90;
Proxy_send_timeout 90;
Proxy_read_timeout 90;
Proxy_buffer_size 4k;
Proxy_buffers 4 32k;
Proxy_busy_buffers_size 64k;
Proxy_temp_file_write_size 64k;
Nginx vhost Virtual Host agent configuration
Location ~* "\. (jsp|do) $ "{
Proxy_pass http://kinggoo.ts;
# Use include to introduce it.
Include proxy.conf;
}
Instance:
If the Nginx listening port is not the default 80 port, change to a different port such as 8181 port.
Request.getserverport () in the back-end server could not get the correct port, the return is still 80;
At Response.sendredirect (), the client may not be able to obtain the correct redirection URL.
The correct configuration method is
Add a port number after the $host, such as $host:8181
server {
Listen 8181;
server_name localhost;
Location/{
Proxy_pass http://147.16.24.175:9500;
Proxy_set_header Host $host: 8181;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}
Reference Help
Nginx built-in variable meaning
Name Version description (variable list from file ngx_http_variables)
$args the parameters in the 1.0.8 request;
$binary _remote_addr 1.0.8 Remote Address binary representation
$body _bytes_sent 1.0.8 Number of message body bytes sent
The "content-length" $content _length 1.0.8 http request information;
$content the "Content-type" in the _type 1.0.8 request information;
$document _root 1.0.8 Set the value for the root path of the current request;
$document _uri 1.0.8 is the same as $uri;
$host the "host" in the 1.0.8 request information, equal to the set server name if there is no host row in the request;
$hostname 1.0.8
$http _cookie 1.0.8 Cookie Information
$http _post 1.0.8
$http _referer 1.0.8 Reference Address
$http _user_agent 1.0.8 Client Agent Information
$http _via 1.0.8 The IP address of the last access server.
$http _x_forwarded_for 1.0.8 corresponds to a network access path.
$is _args 1.0.8
$limit the _rate 1.0.8 to the connection rate;
$nginx _version 1.0.8
$pid 1.0.8
$query _string 1.0.8 is the same as $args;
$realpath _root 1.0.8
$remote _addr 1.0.8 Client address;
$remote _port 1.0.8 Client port number;
$remote _user 1.0.8 Client user name, authentication;
$request 1.0.8 User Requests
$request _body 1.0.8
$request The local file name of the back end of the _body_file 1.0.8
$request _completion 1.0.8
$request _filename 1.0.8 The file path name of the current request
$request _method 1.0.8 Request methods, such as "get", "POST" and so on;
$request the URI of the _uri 1.0.8 request, with parameters;
$scheme 1.0.8 protocols, such as HTTP or HTTPS, such as rewrite^ (. +) [Math processing error]scheme://example.com$1redirect;
$sent _http_cache_control 1.0.8
$sent _http_connection 1.0.8
$sent _http_content_length 1.0.8
$sent _http_content_type 1.0.8
$sent _http_keep_alive 1.0.8
$sent _http_last_modified 1.0.8
$sent _http_location 1.0.8
$sent _http_transfer_encoding 1.0.8
$server _addr 1.0.8 Server address, if the server address is not indicated with listen, use this variable to initiate a system call to get the address (resulting in a waste of resources);
$server _name 1.0.8 The server name to which the request arrived;
$server the server port number on which the _port 1.0.8 request arrives;
$server _protocol 1.0.8 The protocol version requested, "http/1.0" or "http/1.1";
The URI of the $uri 1.0.8 request may differ from the original value, such as redirection
Name Version description (variable list from file ngx_http_variables)
$args the parameters in the 1.0.8 request;
$binary _remote_addr 1.0.8 Remote Address binary representation
$body _bytes_sent 1.0.8 Number of message body bytes sent
The "content-length" $content _length 1.0.8 http request information;
$content the "Content-type" in the _type 1.0.8 request information;
$document _root 1.0.8 Set the value for the root path of the current request;
$document _uri 1.0.8 is the same as $uri;
$host the "host" in the 1.0.8 request information, equal to the set server name if there is no host row in the request;
$hostname 1.0.8
$http _cookie 1.0.8 Cookie Information
$http _post 1.0.8
$http _referer 1.0.8 Reference Address
$http _user_agent 1.0.8 Client Agent Information
$http _via 1.0.8 The IP address of the last access server.
$http _x_forwarded_for 1.0.8 corresponds to a network access path.
$is _args 1.0.8
$limit the _rate 1.0.8 to the connection rate;
$nginx _version 1.0.8
$pid 1.0.8
$query _string 1.0.8 is the same as $args;
$realpath _root 1.0.8
$remote _addr 1.0.8 Client address;
$remote _port 1.0.8 Client port number;
$remote _user 1.0.8 Client user name, authentication;
$request 1.0.8 User Requests
$request _body 1.0.8
$request The local file name of the back end of the _body_file 1.0.8
$request _completion 1.0.8
$request _filename 1.0.8 The file path name of the current request
$request _method 1.0.8 Request methods, such as "get", "POST" and so on;
$request the URI of the _uri 1.0.8 request, with parameters;
$scheme 1.0.8 protocols, such as HTTP or HTTPS, such as rewrite^ (. +) [Math processing error]scheme://example.com$1redirect;
$sent _http_cache_control 1.0.8
$sent _http_connection 1.0.8
$sent _http_content_length 1.0.8
$sent _http_content_type 1.0.8
$sent _http_keep_alive 1.0.8
$sent _http_last_modified 1.0.8
$sent _http_location 1.0.8
$sent _http_transfer_encoding 1.0.8
$server _addr 1.0.8 Server address, if the server address is not indicated with listen, use this variable to initiate a system call to get the address (resulting in a waste of resources);
$server _name 1.0.8 The server name to which the request arrived;
$server the server port number on which the _port 1.0.8 request arrives;
$server _protocol 1.0.8 The protocol version requested, "http/1.0" or "http/1.1";
The URI of the $uri 1.0.8 request may differ from the original value, such as redirection