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

相关文章
相关标签/搜索