上述配置的意思是限制http://host/admin/这个页面只允许被192.168.1.23、192.168.2.20两个IP来访问。
2012.7.16更新
配置了上述参数之后,存在着session丢失的问题,后来稍微做了调整,主要是参数配置所在的位置:
location /
{
proxy_pass http://tomcat;
#root /opt/pthsh/service/WEB-INF/jsp;
root /opt/pthsh/service;
index index.jsp index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream http_502 http_503 http_504 error timeout invalid_header;
proxy_cache nginx_cache;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
proxy_temp_path /opt/nginxtemp;
}
location ~* /admin/.*\.(action|jsp)?$ {
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
allow IP1;
allow IP2/8;
allow IP3;
deny all;
}
location ~* .*\.(action|jsp)?$
{
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
2012.8.22更新
配置成:
location =/admin/login.action {
上述参数之后,存在着在IP(非法IP)切换之后还能保持会话的问题,改成如下解决:
location ~* /admin/ {
这样就保证了正则匹配过滤了。