nginx 逻辑判断if语句使用
当nginx 需要多重过滤转发时,我们会用到逻辑判断if,下面是栗子:
upstream xx-12 {
server ip:8080;
}
server {
listen 8080 ssl;
ssl_certificate /etc/nginx/conf.d/cert.pem;
ssl_certificate_key /etc/nginx/conf.d/key.pem;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
client_max_body_size 50M;
server_name _;
location / {
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml
text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
proxy_connect_timeout 30m;
proxy_send_timeout 1d;
proxy_read_timeout 1d;
proxy_pass https://xx-12;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
if ($http_referer ~* "ip:8080/sm"){
proxy_pass http://xx-12;
break;
}
}
}
if 语句可以过滤下一级路径,从而转发到实际的资源地址。