tomcat做爲服務器的狀況下nginx如何進行請求轉發

當服務器採用nginx+tomcat時,nginx便成了tomcat的客戶端,這時須要配置proxy_pass進行請求的轉發。在使用tomcat做爲web應用程序的服務器時,nginx配置大體以下:html

server{
    listen 80;
	server_name localhost;
	root /usr/local/tomcat/webapps/;
	index index.html index.htm index.jsp;
	location ~\.(jsp|do)${
	    proxy_pass http://127.0.0.1:8080;
		proxy_set_header Host $host;
		proxy_set_header X-client-IP $remote_addr;
	}
}

須要特別說明的是,由於nginx做爲tomcat的客戶端,因此在默認狀況下只能獲取到服務器自己的Host消息頭,故須要經過$host和$remote_addr將用戶客戶端的Host消息頭經nginx傳遞給tomcat,tomcat下運行的應用程序才能獲取到用戶客戶端的消息頭信息。nginx

相關文章
相關標籤/搜索