nginx反向代理表达式的含义

来源:互联网 发布:数据铁笼的概念 编辑:程序博客网 时间:2024/05/29 17:02

nginx配置location [=|~|~*|^~] /uri/ { … }的基本用法表达含义

= 严格匹配。如果这个查询匹配,那么将停止搜索并立即处理此请求。
~ 为区分大小写匹配(可用正则表达式)
!~为区分大小写不匹配
~* 为不区分大小写匹配(可用正则表达式)
!~*为不区分大小写不匹配
^~ 如果把这个前缀用于一个常规字符串,那么告诉nginx 如果路径匹配那么不测试正则表达式。

location = / {
# 只匹配 / 查询。
}
location / {

}
location ^~ /images/ {
# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
}

location~*.(gif|jpg|jpeg)$ {

# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。
}

location ~*.(gif|jpg|swf){  
  valid_referers none blocked start.igrow.cn sta.igrow.cn;  
  if (
invalid_referer) {
#防盗链
rewrite ^/ http://$host/logo.png;
}
}

#user  nobody;worker_processes  1;# 指定工作衍生进程数#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;# 允许的连接数}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  127.0.0.1;        charset utf-8;        location / {            #匹配任何路径            proxy_pass http://localhost:6004;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /baoli/ {            #匹配包含baoli的开头的路径,正则不测试            proxy_pass http://localhost:6001;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /xydd/ {            proxy_pass http://localhost:6009;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /tpmbaoli/ {            proxy_pass http://localhost:6022;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }         location ^~ /tpmxydd/ {            proxy_pass http://localhost:6011;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /wf/ {            proxy_pass http://localhost:6008;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /inventory/ {            proxy_pass http://localhost:6007;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /prd-yyw/ {            proxy_pass http://localhost:6010;            proxy_set_header   Host             $host;            proxy_set_header   X-Real-IP        localhost;            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /gwmgt/ {            proxy_pass http://localhost:6002;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /cdzy/ {            proxy_pass http://localhost:6020;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /cdzytpm/ {            proxy_pass http://localhost:6023;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /sydd/ {            proxy_pass http://localhost:6021;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /cpcn/ {            proxy_pass http://localhost:6015;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /monitor/ {            proxy_pass http://localhost:6014;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        location ^~ /account/ {            proxy_pass http://localhost:6018;            proxy_set_header    Host            $host;            proxy_set_header    X-Real-IP       localhost;            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page  400 404 500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}
原创粉丝点击