nginx和tomcat集群
以下配置可以将动态请求交给后台的tomcat
location ~*\.(jsp|do|action)$ { index index.jsp; proxy_pass http://localhost:9081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~^/(WEB-INF)/{ deny all; }
server { listen 80; server_name www.frady.info *.frady.info; set $htdocs /webapps/yoursite/;#此处定义了htdocs root $htdocs; location / { index index.html index.htm index.action; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ { expires 30d; } location ~*.(jsp|do|action)$ { index index.jsp; proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~^/(WEB-INF)/{ deny all; }}
#以下可以把/helo-frady-mypass.html转发到/hello.action?mts=frady&pwd=mypass#两个一起使用的话,这个得放到前面rewrite "^/hello-([a-z0-9\_]+)-([a-z0-9\_]+)(.*)\.html" /hello.action?mts=$1&pwd=$2;#以下可以把/helo-frady.html转发到/hello.action?mts=fradyrewrite "^/hello-([a-z0-9\_]+)(.*)\.html" /hello.action?mts=$1;if (!-f $request_filename){rewrite (.*) /hello.action; #此配置需要放到location里}if (!-e $request_filename) {rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /hello.action last;}rewrite ^/product/([0-9]+)\.html$ /showWare.action?ware.wareId=$1 last;location / { index index.html index.htm; if (!-f $request_filename){ rewrite (.*) /template.action; } }
upstream myblance { server 192.169.1.100:8080; server 192.169.1.100:28080; ip_hash;#可以实现固定ip访问到固定的后台,解决session的问题 }
server{ listen 80; server_name www.frady.com; location / { proxy_pass http://www.abctest.cn/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}
server { listen 80; server_name *.frady.info ; location / { index index.jsp; proxy_pass http://mybalance; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}