轉自 http://blog.csdn.net/xzknet/article/details/22672127 nginx
Nginx經過80端口反向代理到Tomcat實現很簡單,經過Jsp的request.getServerPort()獲取到的端口號依然是80,而如 果Nginx使用非80端口作反響代理時request.getServerPort()獲取到的端口號返回依然會是80,這樣邊沒法正確 response.sendRedirect後端
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";服務器這樣response.sendRedirect會跳轉到80端口去cookie
解決辦法:網絡
修改proxy.conf獲取你把代理的配置寫到了nginx內,也能夠在其內部修改jsp
proxy_redirect off;ide
# nginx非80端口處理
proxy_set_header Host $host:$server_port;
# 獲取真實IP
proxy_set_header X-Real-IP $remote_addr;
# 獲取代理者的真實ip
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;post
nginx vhost內虛擬主機代理配置spa
location ~* "\.(jsp|do)$" {
proxy_pass http://kinggoo.ts;.net# 使用include引入就能夠了
include proxy.conf;
}
參考幫助
Nginx內置變量含義
名稱 版本 說明(變量列表來源於文件 ngx_http_variables ) $args 1.0.8 請求中的參數; $binary_remote_addr 1.0.8 遠程地址的二進制表示 $body_bytes_sent 1.0.8 已發送的消息體字節數 $content_length 1.0.8 HTTP請求信息裏的"Content-Length"; $content_type 1.0.8 請求信息裏的"Content-Type"; $document_root 1.0.8 針對當前請求的根路徑設置值; $document_uri 1.0.8 與$uri相同; $host 1.0.8 請求信息中的"Host",若是請求中沒有Host行,則等於設置的服務器名; $hostname 1.0.8 $http_cookie 1.0.8 cookie 信息 $http_post 1.0.8 $http_referer 1.0.8 引用地址 $http_user_agent 1.0.8 客戶端代理信息 $http_via 1.0.8 最後一個訪問服務器的Ip地址。 $http_x_forwarded_for 1.0.8 至關於網絡訪問路徑。 $is_args 1.0.8 $limit_rate 1.0.8 對鏈接速率的限制; $nginx_version 1.0.8 $pid 1.0.8 $query_string 1.0.8 與$args相同; $realpath_root 1.0.8 $remote_addr 1.0.8 客戶端地址; $remote_port 1.0.8 客戶端端口號; $remote_user 1.0.8 客戶端用戶名,認證用; $request 1.0.8 用戶請求 $request_body 1.0.8 $request_body_file 1.0.8 發日後端的本地文件名稱 $request_completion 1.0.8 $request_filename 1.0.8 當前請求的文件路徑名 $request_method 1.0.8 請求的方法,好比"GET"、"POST"等; $request_uri 1.0.8 請求的URI,帶參數; $scheme 1.0.8 所用的協議,好比http或者是https,好比rewrite^(.+)$$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 服務器地址,若是沒有用listen指明服務器地址,使用這個變量將發起一次系統調用以取得地址(形成資源浪費); $server_name 1.0.8 請求到達的服務器名; $server_port 1.0.8 請求到達的服務器端口號; $server_protocol 1.0.8 請求的協議版本,"HTTP/1.0"或"HTTP/1.1"; $uri 1.0.8 請求的URI,可能和最初的值有不一樣,好比通過重定向之類的 名稱 版本 說明(變量列表來源於文件 ngx_http_variables ) $args 1.0.8 請求中的參數; $binary_remote_addr 1.0.8 遠程地址的二進制表示 $body_bytes_sent 1.0.8 已發送的消息體字節數 $content_length 1.0.8 HTTP請求信息裏的"Content-Length"; $content_type 1.0.8 請求信息裏的"Content-Type"; $document_root 1.0.8 針對當前請求的根路徑設置值; $document_uri 1.0.8 與$uri相同; $host 1.0.8 請求信息中的"Host",若是請求中沒有Host行,則等於設置的服務器名; $hostname 1.0.8 $http_cookie 1.0.8 cookie 信息 $http_post 1.0.8 $http_referer 1.0.8 引用地址 $http_user_agent 1.0.8 客戶端代理信息 $http_via 1.0.8 最後一個訪問服務器的Ip地址。 $http_x_forwarded_for 1.0.8 至關於網絡訪問路徑。 $is_args 1.0.8 $limit_rate 1.0.8 對鏈接速率的限制; $nginx_version 1.0.8 $pid 1.0.8 $query_string 1.0.8 與$args相同; $realpath_root 1.0.8 $remote_addr 1.0.8 客戶端地址; $remote_port 1.0.8 客戶端端口號; $remote_user 1.0.8 客戶端用戶名,認證用; $request 1.0.8 用戶請求 $request_body 1.0.8 $request_body_file 1.0.8 發日後端的本地文件名稱 $request_completion 1.0.8 $request_filename 1.0.8 當前請求的文件路徑名 $request_method 1.0.8 請求的方法,好比"GET"、"POST"等; $request_uri 1.0.8 請求的URI,帶參數; $scheme 1.0.8 所用的協議,好比http或者是https,好比rewrite^(.+)$$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 服務器地址,若是沒有用listen指明服務器地址,使用這個變量將發起一次系統調用以取得地址(形成資源浪費); $server_name 1.0.8 請求到達的服務器名; $server_port 1.0.8 請求到達的服務器端口號; $server_protocol 1.0.8 請求的協議版本,"HTTP/1.0"或"HTTP/1.1"; $uri 1.0.8 請求的URI,可能和最初的值有不一樣,好比通過重定向之類的 名稱 版本 說明(變量列表來源於文件 ngx_http_variables ) $args 1.0.8 請求中的參數; $binary_remote_addr 1.0.8 遠程地址的二進制表示 $body_bytes_sent 1.0.8 已發送的消息體字節數 $content_length 1.0.8 HTTP請求信息裏的"Content-Length"; $content_type 1.0.8 請求信息裏的"Content-Type"; $document_root 1.0.8 針對當前請求的根路徑設置值; $document_uri 1.0.8 與$uri相同; $host 1.0.8 請求信息中的"Host",若是請求中沒有Host行,則等於設置的服務器名; $hostname 1.0.8 $http_cookie 1.0.8 cookie 信息 $http_post 1.0.8 $http_referer 1.0.8 引用地址 $http_user_agent 1.0.8 客戶端代理信息 $http_via 1.0.8 最後一個訪問服務器的Ip地址。 $http_x_forwarded_for 1.0.8 至關於網絡訪問路徑。 $is_args 1.0.8 $limit_rate 1.0.8 對鏈接速率的限制; $nginx_version 1.0.8 $pid 1.0.8 $query_string 1.0.8 與$args相同; $realpath_root 1.0.8 $remote_addr 1.0.8 客戶端地址; $remote_port 1.0.8 客戶端端口號; $remote_user 1.0.8 客戶端用戶名,認證用; $request 1.0.8 用戶請求 $request_body 1.0.8 $request_body_file 1.0.8 發日後端的本地文件名稱 $request_completion 1.0.8 $request_filename 1.0.8 當前請求的文件路徑名 $request_method 1.0.8 請求的方法,好比"GET"、"POST"等; $request_uri 1.0.8 請求的URI,帶參數; $scheme 1.0.8 所用的協議,好比http或者是https,好比rewrite^(.+)$$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 服務器地址,若是沒有用listen指明服務器地址,使用這個變量將發起一次系統調用以取得地址(形成資源浪費); $server_name 1.0.8 請求到達的服務器名; $server_port 1.0.8 請求到達的服務器端口號; $server_protocol 1.0.8 請求的協議版本,"HTTP/1.0"或"HTTP/1.1"; $uri 1.0.8 請求的URI,可能和最初的值有不一樣,好比通過重定向之類的 名稱 版本 說明(變量列表來源於文件 ngx_http_variables ) $args 1.0.8 請求中的參數; $binary_remote_addr 1.0.8 遠程地址的二進制表示 $body_bytes_sent 1.0.8 已發送的消息體字節數 $content_length 1.0.8 HTTP請求信息裏的"Content-Length"; $content_type 1.0.8 請求信息裏的"Content-Type"; $document_root 1.0.8 針對當前請求的根路徑設置值; $document_uri 1.0.8 與$uri相同; $host 1.0.8 請求信息中的"Host",若是請求中沒有Host行,則等於設置的服務器名; $hostname 1.0.8 $http_cookie 1.0.8 cookie 信息 $http_post 1.0.8 $http_referer 1.0.8 引用地址 $http_user_agent 1.0.8 客戶端代理信息 $http_via 1.0.8 最後一個訪問服務器的Ip地址。 $http_x_forwarded_for 1.0.8 至關於網絡訪問路徑。 $is_args 1.0.8 $limit_rate 1.0.8 對鏈接速率的限制; $nginx_version 1.0.8 $pid 1.0.8 $query_string 1.0.8 與$args相同; $realpath_root 1.0.8 $remote_addr 1.0.8 客戶端地址; $remote_port 1.0.8 客戶端端口號; $remote_user 1.0.8 客戶端用戶名,認證用; $request 1.0.8 用戶請求 $request_body 1.0.8 $request_body_file 1.0.8 發日後端的本地文件名稱 $request_completion 1.0.8 $request_filename 1.0.8 當前請求的文件路徑名 $request_method 1.0.8 請求的方法,好比"GET"、"POST"等; $request_uri 1.0.8 請求的URI,帶參數; $scheme 1.0.8 所用的協議,好比http或者是https,好比rewrite^(.+)$$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 服務器地址,若是沒有用listen指明服務器地址,使用這個變量將發起一次系統調用以取得地址(形成資源浪費); $server_name 1.0.8 請求到達的服務器名; $server_port 1.0.8 請求到達的服務器端口號; $server_protocol 1.0.8 請求的協議版本,"HTTP/1.0"或"HTTP/1.1"; $uri 1.0.8 請求的URI,可能和最初的值有不一樣,好比通過重定向之類的